dpnp.prod

dpnp.prod(a, axis=None, dtype=None, out=None, keepdims=False, initial=None, where=True)[source]

Return the product of array elements over a given axis.

For full documentation refer to numpy.prod.

Parameters:
  • a ({dpnp.ndarray, usm_ndarray}) -- Input array.

  • axis ({None, int or tuple of ints}, optional) -- Axis or axes along which a product is performed. The default, axis=None, will calculate the product of all the elements in the input array. If axis is negative it counts from the last to the first axis. If axis is a tuple of integers, a product is performed on all of the axes specified in the tuple instead of a single axis or all the axes as before. Default: None.

  • dtype ({None, dtype}, optional) -- The type of the returned array, as well as of the accumulator in which the elements are multiplied. The dtype of a is used by default unless a has an integer dtype of less precision than the default platform integer. In that case, if a is signed then the platform integer is used while if a is unsigned then an unsigned integer of the same precision as the platform integer is used. Default: None.

  • out ({None, dpnp.ndarray, usm_ndarray}, optional) -- Alternative output array in which to place the result. It must have the same shape as the expected output, but the type of the output values will be cast if necessary. Default: None.

  • keepdims ({None, bool}, optional) -- If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. Default: False.

Returns:

out -- An array shaped as a but with the specified axis removed. Returns a reference to out if specified.

Return type:

dpnp.ndarray

Limitations

Parameters initial and where are only supported with their default values. Otherwise NotImplementedError exception will be raised.

See also

dpnp.nanprod

Return the product of array elements over a given axis treating Not a Numbers (NaNs) as ones.

Examples

>>> import dpnp as np
>>> np.prod(np.array([1, 2]))
array(2)
>>> a = np.array([[1, 2], [3, 4]])
>>> np.prod(a)
array(24)
>>> np.prod(a, axis=1)
array([ 2, 12])
>>> np.prod(a, axis=0)
array([3, 8])
>>> x = np.array([1, 2, 3], dtype=np.int8)
>>> np.prod(x).dtype == int
True