mean

dragon.vm.torch.mean(
  input,
  dim=None,
  keepdim=False,
  out=None
)[source]

Compute the mean value of elements along the given dimension.

The argument dim could be negative or None:

x = torch.tensor([[1, 2, 3], [4, 5, 6]])

# A negative ``dim`` is the last-k axis
print(torch.mean(x, 1))
print(torch.mean(x, -1))  # Equivalent

# If ``dim`` is None, the vector-style reduction
# will be applied to return a scalar result
print(torch.mean(x))  # Result is 3

# Also, ``dim`` could be a sequence of integers
print(torch.mean(x, [0, 1]))  # Result is 3
Parameters:
  • input (dragon.vm.torch.Tensor) – The input tensor.
  • dim (Union[int, Sequence[int]], optional) – The dimension(s) to reduce.
  • keepdim (bool, optional, default=False) – Keep the reduced dimensions or not.
  • out (dragon.vm.torch.Tensor, optional) – The optional output tensor.
Returns:

dragon.vm.torch.Tensor – The output tensor.