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

Time:01-07

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.

CodePudding user response:

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