edges_analysis.averaging.averaging.bin_array_biased_regular

edges_analysis.averaging.averaging.bin_array_biased_regular(data: ndarray, weights: ndarray | None = None, coords: ndarray | None = None, axis: int = -1, bins: ndarray | int | float | None = None) tuple[ndarray, ndarray, ndarray][source]

Bin arbitrary-dimension data carefully along an axis.

There are multiple ways to “bin” data along an axis when provided with weights. It is not typically accurate to return equi-spaced bins where data is averaged simply via summing with the weights (and the bin coords represent the centre of each bin). This results in some bias when the weights are not uniform.

One way around this is to assume some underlying model and “fill in” the lower-weight bins. This would allow equi-spaced estimates.

However, this function does something simpler – it returns non-equi-spaced bins. This can be a little annoying if multiple data are to be binned, because one needs to keep track of the coordinates of each data separately. However, it is simple and accurate.

Parameters:
  • data – The data to be binned. May be of arbitrary dimension.

  • weights – The weights of the data. Must be the same shape as data. If not provided, assume all weights are unity.

  • coords – The coordinates of the data along the axis to be averaged. If not provided, is taken to be the indices over the axis.

  • axis – The axis over which to bin.

  • bins – The bin edges (lower inclusive, upper not inclusive). If an int, simply use bins samples per bin, starting from the first bin. If a float, use equi-spaced bin edges, starting from the start of coords, and ending past the end of coords. If not provided, assume a single bin encompassing all the data.

Returns:

coords – The weighted average of the coordinates in each bin. If there is no weight in a bin