mindspore.mint.mean

View Source On AtomGit
mindspore.mint.mean(input, *, dtype=None) Tensor[source]

Compute the mean of the tensor.

Parameters

input (Tensor[Number]) – The input tensor.

Keyword Arguments

dtype (mindspore.dtype, optional) – The desired data type of returned tensor. Default None .

Returns

Tensor.

Supported Platforms:

Ascend

Examples

>>> 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[source]

Compute the mean(s) of the tensor along the specified dimension(s).

Note

The dim with tensor type is only used for compatibility with older versions and is not recommended.

Parameters
  • input (Tensor[Number]) – The input tensor.

  • dim (Union[int, tuple(int), list(int), Tensor]) – Specify the dimension(s) for computation.

  • keepdim (bool) – Whether the output tensor has dim retained. Default False .

Keyword Arguments

dtype (mindspore.dtype, optional) – The desired data type of returned tensor. Default None .

Returns

Tensor.

Supported Platforms:

Ascend

Examples

>>> 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.]]]