-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?

0

1 Answer 1

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]])
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.