mindspore.ops.CumProd
- class mindspore.ops.CumProd(exclusive=False, reverse=False)[源代码]
Computes the cumulative product of the tensor x along axis. 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
- Inputs:
x (Tensor[Number]) - The input tensor. \((N,*)\) where \(*\) means, any number of additional dimensions, its rank should be 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.
TypeError – If axis is not an int.
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.]]