Two-dimensional np.digitize

醉酒当歌 提交于 2020-02-23 15:24:53

问题


I have two-dimensional data and I have a bunch of two-dimensional bins generated with scipy.stats.binned_statistic_2d. For each data point, I want the index of the bin it occupies. This is exactly what np.digitize is for, but as far as I can tell, it only deals with one-dimensional data. This stackexchange seems to have an answer, but that is totally generalized to n-dimensions. Is there a more straightforward solution for two dimensions?


回答1:


You can already get the bin index of each observation from the fourth return variable of 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.


来源:https://stackoverflow.com/questions/31635265/two-dimensional-np-digitize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!