有效搜索另一个2d数组中存在的行的二维数组索引。

时间:2018-01-18 20:21:44

标签: python arrays numpy

我有两个2D数组,我希望找到在另一个数组中存在的一个行数组中找到索引的最有效方法。

在以下answer的帮助下,我提出了以下可行的代码,但我认为它可以更有效地完成(我计划在400万像素的数组上使用它):< / p>

import numpy as np

a = np.array([[ 2, 3, 4],
            [ 6, 7, 8],
            [ 7, 10, 9],
            [ 3, 2, 1]])

b = np.array([[ 2, 3, 4],
            [ 7, 10, 9]])

index = []

for elem in b:
    np.where((elem == a).all(axis=1))
    index.append(np.where((elem == a).all(axis=1))[0][0])

0 个答案:

没有答案
相关问题