mindspore.mint.mean

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

计算tensor的均值。

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

关键字参数:
  • dtype (mindspore.dtype, 可选) - 返回的数据类型。默认 None

返回:

Tensor。

支持平台:

Ascend

样例:

>>> import mindspore
>>> import numpy as np
>>> x = mindspore.tensor(np.array([[[2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2]],
... [[4, 4, 4, 4, 4, 4], [5, 5, 5, 5, 5, 5], [6, 6, 6, 6, 6, 6]],
... [[6, 6, 6, 6, 6, 6], [8, 8, 8, 8, 8, 8], [10, 10, 10, 10, 10, 10]]]),
... mindspore.float32)
>>> output = mindspore.mint.mean(x)
>>> print(output)
5.0
>>> print(output.shape)
()
mindspore.mint.mean(input, dim, keepdim=False, *, dtype=None) Tensor[源代码]

计算tensor在指定维度上的均值。

说明

Tensor类型的 dim 仅用作兼容旧版本,不推荐使用。

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

  • dim (Union[int, tuple(int), list(int), Tensor]) - 指定维度。

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

关键字参数:
  • dtype (mindspore.dtype, 可选) - 返回的数据类型。默认 None

返回:

Tensor。

支持平台:

Ascend

样例:

>>> import mindspore
>>> import numpy as np
>>> x = mindspore.tensor(np.array([[[2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2]],
... [[4, 4, 4, 4, 4, 4], [5, 5, 5, 5, 5, 5], [6, 6, 6, 6, 6, 6]],
... [[6, 6, 6, 6, 6, 6], [8, 8, 8, 8, 8, 8], [10, 10, 10, 10, 10, 10]]]),
... mindspore.float32)
>>> output = mindspore.mint.mean(x, 0, True)
>>> print(output)
[[[4. 4. 4. 4. 4. 4.]
  [5. 5. 5. 5. 5. 5.]
  [6. 6. 6. 6. 6. 6.]]]