megengine.Tensor.mean¶
- Tensor.mean(axis=None, keepdims=False)¶
Returns the mean value of each row of the input tensor in the given dimension
axis
.If
axis
is a list of axises, reduce over all of them. Ifkeepdims
isTrue
, the shape of output tensor is the same as the input tensor, except in the dimension(s)axis
where it is of size 1. Otherwise,axis
is squeezed (seesqueeze
).- 参数
axis – the dimension or dimensions to reduce.
keepdims (
bool
) – 输出张量是否保留了轴 ndim 。
- 返回
输出 Tensor.
实际案例
from megengine import tensor a = tensor([False, True, True, False]) b = tensor([1.0, 2.0, 3.0, 4.0]) print(a.mean().numpy()) print(b.mean().numpy())
输出:
0.5 2.5