我有两个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])