pint.utils.weighted_mean
- pint.utils.weighted_mean(arrin, weights_in, inputmean=None, calcerr=False, sdev=False)[source]
Compute weighted mean of input values
Calculate the weighted mean, error, and optionally standard deviation of an input array. By default error is calculated assuming the weights are 1/err^2, but if you send calcerr=True this assumption is dropped and the error is determined from the weighted scatter.
- Parameters:
arrin (array) –
desired. (Array containing the numbers whose weighted mean is) –
weights (array) –
with (A set of weights for each element in array. For measurements) –
uncertainties –
1/sigma^2. (these should be) –
inputmean (float, optional) – An input mean value, around which the mean is calculated.
calcerr (bool, optional) – Calculate the weighted error. By default the error is calculated as 1/sqrt( weights.sum() ). If calcerr=True it is calculated as sqrt((w**2 * (arr-mean)**2).sum() )/weights.sum().
sdev (bool, optional) – If True, also return the weighted standard deviation as a third element in the tuple. Defaults to False.
- Returns:
wmean, werr (tuple)
A tuple of the weighted mean and error. If sdev=True the
tuple will also contain sdev (wmean,werr,wsdev)
Notes
Converted from IDL: 2006-10-23. Erin Sheldon, NYU Copied from PRESTO to PINT : 2020-04-18