mindspore.ops.CumProd
- class mindspore.ops.CumProd(exclusive=False, reverse=False)[source]
Computes the cumulative product of the tensor x along axis.
- Parameters
- Inputs:
x (Tensor[Number]) - The input tensor. \((N,*)\) where \(*\) means, any number of additional dimensions, its rank should less than 8.
axis (int) - The dimensions to compute the cumulative product. Only constant value is allowed.
- Outputs:
Tensor, has the same shape and dtype as the x.
- Raises
TypeError – If exclusive or reverse is not a bool.
ValueError – If axis is None.
- Supported Platforms:
Ascend
GPU
Examples
>>> a, b, c, = 1, 2, 3 >>> x = Tensor(np.array([a, b, c]).astype(np.float32)) >>> op0 = ops.CumProd() >>> output0 = op0(x, 0) # output=[a, a * b, a * b * c] >>> op1 = ops.CumProd(exclusive=True) >>> output1 = op1(x, 0) # output=[1, a, a * b] >>> op2 = ops.CumProd(reverse=True) >>> output2 = op2(x, 0) # output=[a * b * c, b * c, c] >>> op3 = ops.CumProd(exclusive=True, reverse=True) >>> output3 = op3(x, 0) # output=[b * c, c, 1] >>> print(output0) [1. 2. 6.] >>> print(output1) [1. 1. 2.] >>> print(output2) [6. 6. 3.] >>> print(output3) [6. 3. 1.] >>> x = Tensor(np.array([[1, 2, 3], [4, 5, 6], [5, 3, 5]]).astype(np.float32)) >>> output4 = op0(x, 0) >>> output5 = op0(x, 1) >>> print(output4) [[ 1. 2. 3.] [ 4. 10. 18.] [20. 30. 90.]] >>> print(output5) [[1. 2. 6.] [4. 20. 120.] [5. 15. 75.]]