dpnp.cumprod
- dpnp.cumprod(a, axis=None, dtype=None, out=None)[source]
Return the cumulative product of elements along a given axis.
For full documentation refer to
numpy.cumprod
.- Parameters:
a ({dpnp.ndarray, usm_ndarray}) -- Input array.
axis ({None, int}, optional) -- Axis along which the cumulative product is computed. It defaults to compute the cumulative product over the flattened array. Default:
None
.dtype ({None, dtype}, optional) -- Type of the returned array and of the accumulator in which the elements are multiplied. If dtype is not specified, it defaults to the dtype of a, unless a has an integer dtype with a precision less than that of the default platform integer. In that case, the default 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 and buffer length as the expected output but the type will be cast if necessary. Default:
None
.
- Returns:
out -- A new array holding the result is returned unless out is specified as
dpnp.ndarray
, in which case a reference to out is returned. The result has the same size as a, and the same shape as a if axis is notNone
or a is a 1-d array.- Return type:
dpnp.ndarray
See also
dpnp.cumulative_prod
Array API compatible alternative for
dpnp.cumprod
.dpnp.prod
Product array elements.
Examples
>>> import dpnp as np >>> a = np.array([1, 2, 3]) >>> np.cumprod(a) # intermediate results 1, 1*2 ... # total product 1*2*3 = 6 array([1, 2, 6]) >>> a = np.array([[1, 2, 3], [4, 5, 6]]) >>> np.cumprod(a, dtype=np.float32) # specify type of output array([ 1., 2., 6., 24., 120., 720.], dtype=float32)
The cumulative product for each column (i.e., over the rows) of a:
>>> np.cumprod(a, axis=0) array([[ 1, 2, 3], [ 4, 10, 18]])
The cumulative product for each row (i.e. over the columns) of a:
>>> np.cumprod(a, axis=1) array([[ 1, 2, 6], [ 4, 20, 120]])