Solution
extract_BinA = np.ones(B.shape[0]) * -1
for i, b in enumerate(B):
idx = np.argwhere((A == b) == [True, True, True])
if idx.any():
extract_BinA[i] = idx[0][0]
print(extract_BinA)
Explanation
Set extract_BinA to negative values array of size B
extract_BinA = np.ones(B.shape[0]) * -1
In order to get the indices of the elements where B elements equals to A elements, we would need to do the following:
(A == b)
Compares x,y,z for a row in B with every x,y,z rows in A
(A == b) == [True, True, True]
Compares only elements where x_a==x_b, y_a==y_b, and z_a==z_b yields True for all of them
np.argwhere((A == b) == [True, True, True])
Returns a set of indices where the condition is true
A full example to test:
import numpy as np
A = np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12],[13,14,15]])
B = np.array([[0,0,0],[4,5,6],[13,14,15]])
# your code
extract_BinA=np.ones(B.shape[0]) * -1
for i in range(B.shape[0]):
for j in range(A.shape[0]):
if (A[j] == B[i]).all():
extract_BinA[i]=j
print(extract_BinA)
# my code
extract_BinA = np.ones(B.shape[0]) * -1
for i, b in enumerate(B):
idx = np.argwhere((A == b) == [True, True, True])
if idx.any():
extract_BinA[i] = idx[0][0] -----------> changed extract_BinB to extract_BinA
print(extract_BinA)