问题描述
我有二维数据,我有一堆用scipy.stats.binned_statistic_2d
生成的二维箱.对于每个数据点,我想要它占用的bin的索引.这正是np.digitize
的用途,但是据我所知,它仅处理一维数据. 这 stackexchange似乎有一个答案,但这完全可以概括为n维.二维是否有更直接的解决方案?
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?
推荐答案
您已经可以从 scipy.stats.binned_statistic_2d
:
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 : (N,) array of ints or (2,N) ndarray of ints
This assigns to each element of sample an integer that
represents the bin in which this observation falls. The
representation depends on the expand_binnumbers argument.
See Notes for details.
这篇关于二维np.数字化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!