MCPcopy Index your code
hub / github.com/numpy/numpy / cumulative_prod

Function cumulative_prod

numpy/_core/fromnumeric.py:2711–2779  ·  view source on GitHub ↗

Return the cumulative product of elements along a given axis. This function is an Array API compatible alternative to `numpy.cumprod`. Parameters ---------- x : array_like Input array. axis : int, optional Axis along which the cumulative product is computed

(x, /, *, axis=None, dtype=None, out=None,
                    include_initial=False)

Source from the content-addressed store, hash-verified

2709
2710@array_function_dispatch(_cumulative_prod_dispatcher)
2711def cumulative_prod(x, /, *, axis=None, dtype=None, out=None,
2712 include_initial=False):
2713 """
2714 Return the cumulative product of elements along a given axis.
2715
2716 This function is an Array API compatible alternative to `numpy.cumprod`.
2717
2718 Parameters
2719 ----------
2720 x : array_like
2721 Input array.
2722 axis : int, optional
2723 Axis along which the cumulative product is computed. The default
2724 (None) is only allowed for one-dimensional arrays. For arrays
2725 with more than one dimension ``axis`` is required.
2726 dtype : dtype, optional
2727 Type of the returned array, as well as of the accumulator in which
2728 the elements are multiplied. If ``dtype`` is not specified, it
2729 defaults to the dtype of ``x``, unless ``x`` has an integer dtype
2730 with a precision less than that of the default platform integer.
2731 In that case, the default platform integer is used instead.
2732 out : ndarray, optional
2733 Alternative output array in which to place the result. It must
2734 have the same shape and buffer length as the expected output
2735 but the type of the resulting values will be cast if necessary.
2736 See :ref:`ufuncs-output-type` for more details.
2737 include_initial : bool, optional
2738 Boolean indicating whether to include the initial value (ones) as
2739 the first value in the output. With ``include_initial=True``
2740 the shape of the output is different than the shape of the input.
2741 Default: ``False``.
2742
2743 Returns
2744 -------
2745 cumulative_prod_along_axis : ndarray
2746 A new array holding the result is returned unless ``out`` is
2747 specified, in which case a reference to ``out`` is returned. The
2748 result has the same shape as ``x`` if ``include_initial=False``.
2749
2750 Notes
2751 -----
2752 Arithmetic is modular when using integer types, and no error is
2753 raised on overflow.
2754
2755 Examples
2756 --------
2757 >>> a = np.array([1, 2, 3])
2758 >>> np.cumulative_prod(a) # intermediate results 1, 1*2
2759 ... # total product 1*2*3 = 6
2760 array([1, 2, 6])
2761 >>> a = np.array([1, 2, 3, 4, 5, 6])
2762 >>> np.cumulative_prod(a, dtype=np.float64) # specify type of output
2763 array([ 1., 2., 6., 24., 120., 720.])
2764
2765 The cumulative product for each column (i.e., over the rows) of ``b``:
2766
2767 >>> b = np.array([[1, 2, 3], [4, 5, 6]])
2768 >>> np.cumulative_prod(b, axis=0)

Callers

nothing calls this directly

Calls 1

_cumulative_funcFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…