weighted_mean#

bayesflow.utils.weighted_mean(elements: Tensor, weights: Tensor = None) Tensor[source]#

Compute the (optionally) weighted mean of the input tensor.

Parameters:
elementsTensor

A tensor containing the elements to average.

weightsTensor, optional

A tensor of the same shape as elements representing weights. If None, the mean is computed without weights.

Returns:
Tensor

A scalar tensor representing the (weighted) mean.