0
如何查找两个numpy数组之间精确匹配的行的索引。例如:查找两个numpy数组中匹配行的索引
x = np.array(([0,1],
[1,0],
[0,0]))
y = np.array(([0,1],
[1,1],
[0,0]))
这应返回:
matches = [0,2] # Match at row no 0 and 2
如何查找两个numpy数组之间精确匹配的行的索引。例如:查找两个numpy数组中匹配行的索引
x = np.array(([0,1],
[1,0],
[0,0]))
y = np.array(([0,1],
[1,1],
[0,0]))
这应返回:
matches = [0,2] # Match at row no 0 and 2
np.flatnonzero((x == y).all(1))
# array([0, 2])
或:
np.nonzero((x == y).all(1))[0]
或:
np.where((x == y).all(1))[0]
这适用于每对numpy阵列,如果长度相同:
matches = [i for i in range(len(x)) if x[i].tolist()==y[i].tolist()]