Search for duplicated rows in two numpy arrays with different length (Python)

Question:

I have two numpy arrays with different length.

array([['A', 'B'],
       ['C', 'D'],
       ['E', 'F']])


array([['B', 'A'],
       ['C', 'E']])

What I want is to see is if they have common rows, BUT not consider the order. So in the above two arrays, ‘A’ ‘B’ and ‘B’ ‘A’ are duplicates.

Asked By: AN_

||

Answers:

A possible solution, where a1 and a2 are the first and second arrays, respectively:

a1[np.isin(a1, a2).all(axis=1)]

Output:

array([['A', 'B']], dtype='<U1')
Answered By: PaulS
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.