mindspore.numpy.mean
- mindspore.numpy.mean(a, axis=None, keepdims=False, dtype=None)[源代码]
Computes the arithmetic mean along the specified axis.
Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis.
说明
Numpy arguments out is not supported. On GPU, the supported dtypes are np.float16, and np.float32.
- 参数
a (Tensor) – input tensor containing numbers whose mean is desired. If a is not an array, a conversion is attempted.
axis (None or int or tuple of integers, optional) – Axis or axes along which the means are computed. The default is to compute the mean of the flattened array. If this is a tuple of ints, a mean is performed over multiple axes.
keepdims (bool, optional) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input tensor.
dtype (
mindspore.dtype
, optional) – Defaults to None. Overrides the dtype of the output Tensor.
- 返回
Tensor or scalar, an array containing the mean values.
- 异常
ValueError – If axes are out of the range of
[-a.ndim, a.ndim)
, or if the axes contain duplicates.
- Supported Platforms:
Ascend
GPU
CPU
样例
>>> import mindspore.numpy as np >>> a = np.arange(6, dtype='float32') >>> output = np.mean(a, 0) >>> print(output) 2.5