有人问过类似的问题,但没有一个答案能满足我的需要——有些答案允许多维搜索(matlab中的“行”选项),但不返回索引。有些返回索引但不允许行。我的数组非常大(1米x 2),我成功地制作了一个循环,但显然这是非常缓慢的。在matlab中,内置的ismember函数大约需要10秒。在
我要找的是:
a=np.array([[4, 6],[2, 6],[5, 2]])
b=np.array([[1, 7],[1, 8],[2, 6],[2, 1],[2, 4],[4, 6],[4, 7],[5, 9],[5, 2],[5, 1]])
具体的matlab函数是:
^{pr2}$在哪里
index = [6, 3, 9]
该函数首先将多个元素列转换为一个列数组,然后数字1英寸可以用来找出想要的答案,请尝试以下代码:
打印
^{pr2}$我用广播
[更新]
^{3}$正如unutbu所说,指数是按递增顺序返回的
印刷品
^{pr2}$这相当于Matlab的[3,6,9],因为Python使用基于0的索引。在
一些注意事项:
b
中a
项的位置。在asvoid([-0.]) == asvoid([0.])
返回array([False])
。在尽管有这些注意事项,但为了速度起见,还是可以选择使用
^{3}$in1d_index
:因此}返回{}在{中显示的顺序行中的索引。在
in1d_index
比in1d_index
快了大约65倍(对于长度为低千分之一的数组),但是再次注意,这种比较并不完全是苹果对苹果,因为in1d_index
以递增顺序返回索引,而{相关问题 更多 >
编程相关推荐