Suppose I have an array a and b, how can I find the identical element in both arrays?
a = np.array([[262.5, 262.5, 45],
[262.5, 262.5, 15],
[262.5, 187.5, 45],
[262.5, 187.5, 15],
[187.5, 262.5, 45],
[187.5, 262.5, 15],
[187.5, 187.5, 45],
[187.5, 187.5, 15]])
b = np.array([[262.5, 262.5, 45],
[262.5, 262.5, 15],
[3,3,5],
[5,5,7],
[8,8,9]])
I tried the code below, but the output is not what I want, can anyone tell me what is wrong with this code? or is there any other way to do it?
out = [x[(x == b[:,None]).all(1).any(0)] for x in a]
The output I want is:
array[[262.5, 262.5, 45],
[262.5, 262.5, 15]]
>Solution :
a[np.all([np.isin(ai, b) for ai in a], axis=1)]
or also:
b[np.all([np.isin(bi, a) for bi in b], axis=1)]