Shortcuts

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 a int nor a torch.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)

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources