bin_nd

typhon.math.stats.bin_nd(binners, bins, data=None)[source]

Bin/bucket data in arbitrary number of dimensions

For example, one can bin geographical data according to lat/lon through:

>>> binned = bin_nd([lats, lons], [lat_bins, lon_bins])

The actually binned data are the indices for the arrays lats/lons, which hopefully corresponds to indices in your actual data.

Data that does not fit in any bin, is not binned anywhere.

You can use this for geographical data, but if your x and y are in lat/lons the bins will be equirectangular (if you want equal-area bins you will have to reproject / change coordinates).

Note: do NOT pass the 3rd argument, data. This is used purely for the implementation using recursion. Passing anything here explicitly is a recipe for disaster.

Parameters
  • binners (List[ndarray]) – Axes that data is binned at. This is akin to the x-coordinate in :func:bin.

  • bins (List[ndarray]) – Edges for the bins according to which bin data.

Returns

n-D ndarray of type object, with indices describing what bin elements belong to.