edges_analysis.averaging.averaging.bin_data¶
- edges_analysis.averaging.averaging.bin_data(data: ndarray, residuals: ndarray | None = None, weights: ndarray | None = None, bins: list[ndarray | slice] | None = None, axis: int = -1) tuple[ndarray, ndarray, ndarray] [source]¶
Bin data, in an un-biased way if possible.
This uses the estimator from memo #183: http://loco.lab.asu.edu/wp-content/uploads/2020/10/averaging_with_weights.pdf.
- Parameters:
data – The data to be binned.
residuals – The residuals of the data, if known. If not provided, and weights is non uniform, the average will be biased.
weights – The weights of the data. If not provided, assume all weights are unity.
bins – The bins into which to bin the data. If not provided, assume a single bin encompassing all the data. Each element should be either an array that indexes into the axis over which to bin, or a slice object.
axis – The axis over which to bin.
- Returns:
data – The binned data.
weights – The weights of the binned data.
residuals – The binned residuals (if provided).