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, its rank should be less than 8.

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

  • dtype – The desired data type of output. Default: None.

Returns

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

Raises
Supported Platforms:

Ascend CPU GPU

Examples

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