mindspore.ops.prod
- mindspore.ops.prod(input, axis=None, keep_dims=False, dtype=None)[source]
Return the product(s) of the tensor along the specified axis(axes).
- Parameters
input (Tensor[Number]) – The input tensor.
axis (Union[int, tuple(int), list(int), Tensor]) – Specify the axis(axes) for computation. If
None
, compute all elements in the input . DefaultNone
.keep_dims (bool) – Whether the output tensor has dim retained. Default
False
.dtype (
mindspore.dtype
) – The data type returned. DefaultNone
.
- Returns
Tensor
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> input = mindspore.tensor([[9, 3, 4, 5], ... [5, 2, 7, 4], ... [8, 1, 3, 6]]) >>> # case 1: By default, compute the product of all elements. >>> mindspore.ops.prod(input) Tensor(shape=[], dtype=Int64, value= 21772800) >>> >>> # case 2: Compute the product along axis 1. >>> mindspore.ops.prod(input, axis=1) Tensor(shape=[3], dtype=Int64, value= [540, 280, 144]) >>> >>> # case 3: If keep_dims=True, the output shape will be same of that of the input. >>> mindspore.ops.prod(input, axis=1, keep_dims=True) Tensor(shape=[3, 1], dtype=Int64, value= [[540], [280], [144]])