mindspore.ops.mean
- mindspore.ops.mean(x, axis=None, keep_dims=False)[源代码]
计算tensor在指定轴上的均值。
- 参数:
x (Tensor[Number]) - 输入tensor。
axis (Union[int, tuple(int), list(int), Tensor]) - 指定计算轴。如果为
None
,计算 input 中的所有元素。默认None
。keep_dims (bool) - 输出tensor是否保留维度。默认
False
。
- 返回:
Tensor
- 支持平台:
Ascend
GPU
CPU
样例:
>>> import mindspore >>> input = mindspore.tensor([[9, 3, 4, 5], ... [5, 2, 7, 4], ... [8, 1, 3, 6]]) >>> # case 1: By default, compute the mean of all elements. >>> mindspore.ops.mean(input) Tensor(shape=[], dtype=Int64, value= 4) >>> >>> # case 2: Compute the mean along axis 1. >>> mindspore.ops.mean(input, axis=1) Tensor(shape=[3], dtype=Int64, value= [5, 4, 4]) >>> >>> # case 3: If keep_dims=True, the output shape will be same of that of the input. >>> mindspore.ops.mean(input, axis=1, keep_dims=True) Tensor(shape=[3, 1], dtype=Int64, value= [[5], [4], [4]])