mindspore.ops.cumprod

mindspore.ops.cumprod(input, dim, dtype=None)[source]

Computes the cumulative product of the input tensor along dimension dim. For example, if input is a vector of size N, the result will also be a vector of size N, with elements.

\[y_i = x_1 * x_2 * x_3 * ... * x_i\]
Parameters
  • input (Tensor[Number]) – The input tensor. \((N,*)\) where \(*\) means, any number of additional dimensions.

  • dim (int) – The dimensions to compute the cumulative product. Only constant value is allowed.

  • dtype (mindspore.dtype, optional) – The desired data type of output. If not specified, remains the same as the original Tensor. Default: None.

Returns

Tensor, has the same shape and dtype as the input unless dtype is specified.

Raises
Supported Platforms:

Ascend GPU CPU

Examples

>>> x = Tensor(np.array([1, 2, 3], np.float32))
>>> output = ops.cumprod(x, 0)
>>> print(output)
[1. 2. 6.]