mindspore.mint.prod

查看源文件
mindspore.mint.prod(input, *, dtype=None) Tensor[源代码]

计算tensor所有元素的乘积。

参数:
  • input (Tensor[Number]) - 输入tensor。

关键字参数:
返回:

Tensor。

支持平台:

Ascend

样例:

>>> import mindspore
>>> x = mindspore.tensor([[[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 = mindspore.mint.prod(x)
>>> print(output)
2.2833798e+33
>>> print(output.shape)
()
mindspore.mint.prod(input, dim, keepdim=False, *, dtype=None) Tensor[源代码]

默认情况下,使用指定维度的所有元素的乘积代替该维度的其他元素,以移除该维度。也可仅缩小该维度大小至1。 keepdim 控制输出和输入的维度是否相同。

参数:
  • input (Tensor[Number]) - 输入tensor。

  • dim (int) - 指定计算维度。

  • keepdim (bool) - 输出tensor是否保留维度。默认 False

关键字参数:
返回:

Tensor。

  • 如果 dim 为int,取值为1,并且 keepdimFalse ,则输出的shape为 \((input_0, input_2, ..., input_R)\)

异常:
  • ValueError - dim 超出范围。

支持平台:

Ascend

样例:

>>> import mindspore
>>> x = mindspore.tensor([[[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)
>>> mindspore.mint.prod(x, 0, True)
Tensor(shape=[1, 3, 6], dtype=Float32, value=
[[[ 2.80000000e+01,  2.80000000e+01,  2.80000000e+01,  2.80000000e+01,  2.80000000e+01,  2.80000000e+01],
  [ 8.00000000e+01,  8.00000000e+01,  8.00000000e+01,  8.00000000e+01,  8.00000000e+01,  8.00000000e+01],
  [ 1.62000000e+02,  1.62000000e+02,  1.62000000e+02,  1.62000000e+02,  1.62000000e+02,  1.62000000e+02]]])