bundles / numpy latest / numpy / cumulative_prod
_ArrayFunctionDispatcher
numpy:cumulative_prod
source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/_core/fromnumeric.py :2672
Signature
def cumulative_prod ( x , / , axis = None , dtype = None , out = None , include_initial = False ) Summary
Return the cumulative product of elements along a given axis.
Extended Summary
This function is an Array API compatible alternative to numpy.cumprod.
Parameters
x: array_likeInput array.
axis: int, optionalAxis along which the cumulative product is computed. The default (None) is only allowed for one-dimensional arrays. For arrays with more than one dimension
axisis required.dtype: dtype, optionalType of the returned array, as well as of the accumulator in which the elements are multiplied. If
dtypeis not specified, it defaults to the dtype ofx, unlessxhas an integer dtype with a precision less than that of the default platform integer. In that case, the default platform integer is used instead.out: ndarray, optionalAlternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type of the resulting values will be cast if necessary. See
ufuncs-output-typefor more details.include_initial: bool, optionalBoolean indicating whether to include the initial value (ones) as the first value in the output. With
include_initial=Truethe shape of the output is different than the shape of the input. Default:False.
Returns
cumulative_prod_along_axis: ndarrayA new array holding the result is returned unless
outis specified, in which case a reference tooutis returned. The result has the same shape asxifinclude_initial=False.
Notes
Arithmetic is modular when using integer types, and no error is raised on overflow.
Examples
a = np.array([1, 2, 3]) np.cumulative_prod(a) # intermediate results 1, 1*2 # total product 1*2*3 = 6 a = np.array([1, 2, 3, 4, 5, 6])✓
np.cumulative_prod(a, dtype=float) # specify type of output
✗b = np.array([[1, 2, 3], [4, 5, 6]]) np.cumulative_prod(b, axis=0)✓
np.cumulative_prod(b, axis=1)
✓Aliases
-
numpy.cumulative_prod