您可以从第四个返回变量获取每个观察的bin索引scipy.stats.binned_statistic_2d:
Run Code Online (Sandbox Code Playgroud)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.