mindspore.mint.prod
- mindspore.mint.prod(input, *, dtype=None) Tensor [source]
Multiplying all elements of input.
- Parameters
input (Tensor[Number]) – The input tensor. The dtype of the tensor to be reduced is number. \((N, *)\) where \(*\) means, any number of additional dimensions.
- Keyword Arguments
dtype (
mindspore.dtype
, optional) – The desired data type of returned Tensor. Default:None
.- Returns
Tensor.
- Raises
TypeError – If input is not a Tensor.
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor, mint >>> x = Tensor(np.array([[[1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2], [3, 3, 3, 3, 3, 3]], ... [[4, 4, 4, 4, 4, 4], [5, 5, 5, 5, 5, 5], [6, 6, 6, 6, 6, 6]], ... [[7, 7, 7, 7, 7, 7], [8, 8, 8, 8, 8, 8], [9, 9, 9, 9, 9, 9]]]), mindspore.float32) >>> output = mint.prod(x) >>> print(output) 2.2833798e+33 >>> print(output.shape) ()
Reduces a dimension of a tensor by multiplying all elements in the dimension, by default. And also can reduce a dimension of input along the dim. Determine whether the dimensions of the output and input are the same by controlling keepdim.
- Parameters
input (Tensor[Number]) – The input tensor. The dtype of the tensor to be reduced is number. \((N, *)\) where \(*\) means, any number of additional dimensions.
dim (int) – The dimensions to reduce. Only constant value is allowed. Assume the rank of x is r, and the value range is [-r,r).
keepdim (bool) – If
True
, keep these reduced dimensions and the length is 1. IfFalse
, don't keep these dimensions. Default:False
.
- Keyword Arguments
dtype (
mindspore.dtype
, optional) – The desired data type of returned Tensor. Default:None
.- Returns
Tensor.
If dim is int, set as 1, and keepdim is
False
, the shape of output is \((input_0, input_2, ..., input_R)\).
- Raises
TypeError – If input is not a Tensor.
TypeError – If dim is not int.
TypeError – If keepdim is not a bool.
ValueError – If dim is out of range.
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor, mint >>> x = Tensor(np.array([[[1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2], [3, 3, 3, 3, 3, 3]], ... [[4, 4, 4, 4, 4, 4], [5, 5, 5, 5, 5, 5], [6, 6, 6, 6, 6, 6]], ... [[7, 7, 7, 7, 7, 7], [8, 8, 8, 8, 8, 8], [9, 9, 9, 9, 9, 9]]]), mindspore.float32) >>> output = mint.prod(x, 0, True) >>> print(output) [[[ 28. 28. 28. 28. 28. 28.] [ 80. 80. 80. 80. 80. 80.] [162. 162. 162. 162. 162. 162.]]]