Overview
Purpose
Compute the arithmetic mean of x or, if w is provided, the weighted mean.
Parameters
x: numeric data.w: optional weights. They must have the same shape asxand be strictly positive.
Returns
A float with the simple or weighted mean.
Errors and exceptions
ValueErrorifxis empty or not finite.ValueErrorifwhas an incompatible shape.ValueErrorifwcontains non-positive values or has a non-positive sum.
Example
from mespy import weighted_mean
x = [1.0, 2.0, 3.0]
w = [3.0, 1.0, 1.0]
print(weighted_mean(x)) # 2.0
print(weighted_mean(x, w)) # 1.6
Notes
If
w is None, the function usesnumpy.mean.Weight validation goes through
_validate_weights.