weighted_mean

sofia_redux.toolkit.resampling.weighted_mean(data, weights, weightsum=None)[source]

Calculate the weighted mean of a data set.

The weighted mean of data \(y\) with weights \(w\) is given as:

\[\bar{y} = \frac{\sum_{i=1}^{N}{w_i y_i}} {\sum_{i=1}^{N}{w_i}}\]

This is a jit compiled numba function for use within other functions in sofia_redux.toolkit.resampling.

Parameters:
datanumpy.ndarray (ndata,)

Data.

weightsnumpy.ndarray (ndata,)

Weights.

weightsumint or float, optional

Sum of weights, optionally passed in for speed if pre-calculated.

Returns:
weighted_meanfloat

The weighted mean.