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

Weights aligned with the leading (batch) axis of elements, e.g., of shape (batch_size,) or (batch_size, 1). If None, the mean is computed without weights.

Returns:
Tensor

A scalar tensor representing the (weighted) mean.