二维np.数字化 [英] Two-dimensional np.digitize

查看:52
本文介绍了二维np.数字化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有二维数据,我有一堆用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?

推荐答案

您已经可以从

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.数字化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆