mean(input, dim=None, keepdim=False) → Tensor¶
Computes the mean of row of elements in a tensor in the given dimension. If the dimension is None, mean of all elements will be caculated.
If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed
oneflow.squeeze(), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s).
input (oneflow.Tensor) – the Input Tensor
dim (int or tuple of ints, optional) – the dimension to reduce. Default: None
keepdim (bool, optional) – whether the output tensor has dim retained or not. Default: False
>>> import oneflow as flow >>> input = flow.Tensor([[1, 2, 3], [4, 5, 6]]) >>> flow.mean(input) tensor(3.5000, dtype=oneflow.float32) >>> flow.mean(input, dim=0) tensor([2.5000, 3.5000, 4.5000], dtype=oneflow.float32) >>> flow.mean(input, dim=1) tensor([2., 5.], dtype=oneflow.float32)