torcheval.metrics.functional.mean¶
- torcheval.metrics.functional.mean(input: Tensor, weight: float | int | Tensor = 1.0) Tensor ¶
Compute weighted mean. When weight is not provided, it calculates the unweighted mean. Its class version is
torcheval.metrics.Mean
.weighted_mean = sum(weight * input) / sum(weight)
- Parameters:
input (Tensor) – Tensor of input values.
weight (optional) – Float or Int or Tensor of input weights. It is default to 1.0. If weight is a Tensor, its size should match the input tensor size.
- Raises:
ValueError – If value of weight is neither a
float
nor aint
nor atorch.Tensor
that matches the input tensor size.
Examples:
>>> import torch >>> from torcheval.metrics.functional import mean >>> mean(torch.tensor([2, 3])) tensor(2.5) >>> mean(torch.tensor([2, 3]), torch.tensor([0.2, 0.8])) tensor(2.8) >>> mean(torch.tensor([2, 3]), 0.5) tensor(2.5) >>> mean(torch.tensor([2, 3]), 1) tensor(2.5)