mygrad.cumprod#

mygrad.cumprod(a: ArrayLike, axis: Union[None, int, Tuple[int, ...]] = None, *, constant: Optional[bool] = None) Tensor[source]#

Return the cumulative product of elements along a given axis.

This docstring was adapted from the official numpy documentation

Parameters
aArrayLike

Input array.

axisOptional[int]

Axis along which the cumulative product is computed. By default the input is flattened.

constantbool, optional(default=False)

If True, the returned tensor is a constant (it does not back-propagate a gradient)

constantOptional[bool]

If True, this tensor is treated as a constant, and thus does not facilitate back propagation (i.e. constant.grad will always return None).

Defaults to False for float-type data. Defaults to True for integer-type data.

Integer-type tensors must be constant.

Returns
mygrad.Tensor

Notes

Arithmetic is modular when using integer types, and no error is raised on overflow.

Examples

>>> from mygrad import cumprod, Tensor
>>> a = Tensor([[1, 2, 3],
...             [4, 5, 6]])
>>> cumprod(a)
Tensor([  1   2   6  24 120 720])

The cumulative product for each column (i.e., over the rows) of a:

>>> cumprod(a, axis=0)
Tensor([[ 1,  2,  3],
       [ 4, 10, 18]])

The cumulative product for each row (i.e. over the columns) of a:

>>> cumprod(a, axis=1)
Tensor([[  1,   2,   6],
        [  4,  20, 120]])