mindspore.ops.prod
- mindspore.ops.prod(input, axis=None, keep_dims=False, dtype=None)[源代码]
返回tensor在指定轴上的乘积。
- 参数:
input (Tensor[Number]) - 输入tensor。
axis (Union[int, tuple(int), list(int), Tensor]) - 指定计算轴。如果为
None
,计算 input 中的所有元素。默认None
。keep_dims (bool) - 输出tensor是否保留维度。默认
False
。dtype (
mindspore.dtype
) - 返回的数据类型。默认None
。
- 返回:
Tensor
- 支持平台:
Ascend
GPU
CPU
样例:
>>> 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]])