prod¶
- prod(x: array, /, *, axis: int | Tuple[int, ...] | None = None, dtype: dtype | None = None, keepdims: bool = False) array ¶
Calculates the product of input array
x
elements.- Parameters:
x (array) – input array. Should have a numeric data type.
axis (Optional[Union[int, Tuple[int, ...]]]) – axis or axes along which to compute products. By default, the product must be computed over the entire array. If a tuple of integers, products must be computed over multiple axes. A valid axis must be an integer on the interval
[-N, N)
, whereN
is the number of axes inx
. If an axis is specified as a negative integer, the function must determine the axis along which to perform the operation by counting backward from the last axis (where-1
refers to the last axis). If provided an invalid axis, the function must raise an exception. Default:None
.dtype (Optional[dtype]) –
data type of the returned array. If
None
, the returned array must have the same data type asx
, unlessx
has an integer data type supporting a smaller range of values than the default integer data type (e.g.,x
has anint16
oruint32
data type and the default integer data type isint64
). In those latter cases:if
x
has a signed integer data type (e.g.,int16
), the returned array must have the default integer data type.if
x
has an unsigned integer data type (e.g.,uint16
), the returned array must have an unsigned integer data type having the same number of bits as the default integer data type (e.g., if the default integer data type isint32
, the returned array must have auint32
data type).
If the data type (either specified or resolved) differs from the data type of
x
, the input array should be cast to the specified data type before computing the sum (rationale: thedtype
keyword argument is intended to help prevent overflows). Default:None
.keepdims (bool) – if
True
, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, ifFalse
, the reduced axes (dimensions) must not be included in the result. Default:False
.
- Returns:
out (array) – if the product is computed over the entire array, a zero-dimensional array containing the product; otherwise, a non-zero-dimensional array containing the products. The returned array must have a data type as described by the
dtype
parameter above.
Notes
Special Cases
Let
M
equal the number of elements over which to compute the product.If
M
is0
, the product must be1
(i.e., the empty product).
For both real-valued and complex floating-point operands, special cases must be handled as if the operation is implemented by successive application of
multiply()
.Changed in version 2022.12: Added complex data type support.
Changed in version 2023.12: Required the function to return a floating-point array having the same data type as the input array when provided a floating-point array.