giagrad.Tensor.mean#

Tensor.mean(axis=None, keepdims=False) Tensor[source]#

Returns the mean value of each 1-D slice of the tensor in the given axis, if axis is a list of dimensions, reduce over all of them.

If keepdims is True, the output tensor is of the same size as input except in the axis where it is of size 1. Otherwise, every axis is squeezed, leading to an output tensor with fewer dimensions. If no axis is supplied all data is reduced to a scalar value.

Parameters:
  • axis ((int, ...) or int or None, default: None) – The dimension or dimension to reduce. If None, mean reduces all dimensions.

  • keepdims (bool, default: False) – Whether te output tensor should retain the reduced dimensions.

Examples

>>> t = Tensor(np.arange(12).reshape((2,2,3)))
>>> t
tensor: [[[ 0.  1.  2.]
          [ 3.  4.  5.]]
...
         [[ 6.  7.  8.]
          [ 9. 10. 11.]]]
>>> t.mean(axis=(0, 1), keepdims=True)
tensor: [[[4.5 5.5 6.5]]] fn: Mean(axis=(0, 1))