-1

For example, I have two arrays

A= [[1,0],[2,0],[3,0]]
B=[[2,1],[2,0],[3,0]]

np.intersect1d(A,B) gives me 0,1,2,3, but what I actually want is [2,0] and [3,0]. What can I do in this case?

sacuL
  • 49,704
  • 8
  • 81
  • 106
xyseverus
  • 1
  • 1

1 Answers1

0

Here is one way:

set([tuple(row) for row in A]).intersection([tuple(row) for row in B])

{(3, 0), (2, 0)}

You can then get this as an np.array like this:

tups = set([tuple(row) for row in A]).intersection([tuple(row) for row in B])

result = np.array([tup for tup in tups])

>>> result
array([[3, 0],
       [2, 0]])
sacuL
  • 49,704
  • 8
  • 81
  • 106