AN_
AN_

Reputation: 143

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

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.

Upvotes: 0

Views: 42

Answers (1)

PaulS
PaulS

Reputation: 25313

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')

Upvotes: 1

Related Questions