pint.utils.weighted_mean
- pint.utils.weighted_mean(arrin: ndarray, weights_in: ndarray, inputmean: float | None = None, calcerr: bool = False, sdev: bool = False) Tuple[float, ...][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) – Array containing the numbers whose weighted mean is desired.
weights (array) – A set of weights for each element in array. For measurements with uncertainties, these should be 1/sigma^2.
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 – A tuple of the weighted mean and error. If sdev=True the tuple will also contain sdev: wmean,werr,wsdev
- Return type:
Notes
Converted from IDL: 2006-10-23. Erin Sheldon, NYU Copied from PRESTO to PINT : 2020-04-18