MCPcopy Create free account
hub / github.com/numpy/numpy / cumprod

Function cumprod

numpy/core/fromnumeric.py:3109–3169  ·  view source on GitHub ↗

Return the cumulative product of elements along a given axis. Parameters ---------- a : array_like Input array. axis : int, optional Axis along which the cumulative product is computed. By default the input is flattened. dtype : dtype, optional

(a, axis=None, dtype=None, out=None)

Source from the content-addressed store, hash-verified

3107
3108@array_function_dispatch(_cumprod_dispatcher)
3109def cumprod(a, axis=None, dtype=None, out=None):
3110 """
3111 Return the cumulative product of elements along a given axis.
3112
3113 Parameters
3114 ----------
3115 a : array_like
3116 Input array.
3117 axis : int, optional
3118 Axis along which the cumulative product is computed. By default
3119 the input is flattened.
3120 dtype : dtype, optional
3121 Type of the returned array, as well as of the accumulator in which
3122 the elements are multiplied. If *dtype* is not specified, it
3123 defaults to the dtype of `a`, unless `a` has an integer dtype with
3124 a precision less than that of the default platform integer. In
3125 that case, the default platform integer is used instead.
3126 out : ndarray, optional
3127 Alternative output array in which to place the result. It must
3128 have the same shape and buffer length as the expected output
3129 but the type of the resulting values will be cast if necessary.
3130
3131 Returns
3132 -------
3133 cumprod : ndarray
3134 A new array holding the result is returned unless `out` is
3135 specified, in which case a reference to out is returned.
3136
3137 See Also
3138 --------
3139 :ref:`ufuncs-output-type`
3140
3141 Notes
3142 -----
3143 Arithmetic is modular when using integer types, and no error is
3144 raised on overflow.
3145
3146 Examples
3147 --------
3148 >>> a = np.array([1,2,3])
3149 >>> np.cumprod(a) # intermediate results 1, 1*2
3150 ... # total product 1*2*3 = 6
3151 array([1, 2, 6])
3152 >>> a = np.array([[1, 2, 3], [4, 5, 6]])
3153 >>> np.cumprod(a, dtype=float) # specify type of output
3154 array([ 1., 2., 6., 24., 120., 720.])
3155
3156 The cumulative product for each column (i.e., over the rows) of `a`:
3157
3158 >>> np.cumprod(a, axis=0)
3159 array([[ 1, 2, 3],
3160 [ 4, 10, 18]])
3161
3162 The cumulative product for each row (i.e. over the columns) of `a`:
3163
3164 >>> np.cumprod(a,axis=1)
3165 array([[ 1, 2, 6],
3166 [ 4, 20, 120]])

Callers 1

cumproductFunction · 0.85

Calls 1

_wrapfuncFunction · 0.85

Tested by

no test coverage detected