mindspore.mint.mean
- 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. DefaultNone.- 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) ()
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
- Keyword Arguments
dtype (
mindspore.dtype, optional) – The desired data type of returned tensor. DefaultNone.- 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.]]]