2D np.digitize

I have 2D data and I have a bunch of 2D boxes generated with scipy.stats.binned_statistic_2d

. For each data point, I want the index of the bin it occupies. This is exactly what it is for np.digitize

, but as far as I can tell, it only deals with 1D data. This stackexchange seems to have an answer, but it is completely generalized to n-dimensional. Is there a simpler solution for two dimensions?

+3


source to share


1 answer


You can already get the bin index of each observation from the fourth return variable scipy.stats.binned_statistic_2d

:



Returns:  
  statistic : (nx, ny) ndarray
      The values of the selected statistic in each two-dimensional bin
  xedges : (nx + 1) ndarray
      The bin edges along the first dimension.
  yedges : (ny + 1) ndarray
      The bin edges along the second dimension.
  binnumber : 1-D ndarray of ints
      This assigns to each observation an integer that represents the bin
      in which this observation falls. Array has the same length as values.

      

+3


source







All Articles