edges_cal.tools.bin_array

edges_cal.tools.bin_array(x: ndarray, size: int = 1) ndarray[source]

Simple unweighted mean-binning of an array.

Parameters:
  • x – The array to be binned. Only the last axis will be binned.

  • size – The size of the bins.

Notes

The last axis of x is binned. It is assumed that the coordinates corresponding to x are regularly spaced, so the final average just takes size values and averages them together.

If the array is not divisible by size, the last values are left out.

Examples

Simple 1D example:

>>> x = np.array([1, 1, 2, 2, 3, 3])
>>> bin_array(x, size=2)
[1, 2, 3]

The last remaining values are left out:

>>> x = np.array([1, 1, 2, 2, 3, 3, 4])
>>> bin_array(x, size=2)
[1, 2, 3]