0

I have 2 numpy arrays. Eg.

A = [[1,2],[3,4],[5,6]]
B = [[5,6],[1,4],[6,5],[1,2]]

I want to get the matching elements in the 2 arrays. i.e [[1,2],[5,6]]

The arrays that I am using in my code are very large. Is there any fast way of implementing it, without using for loop and comparing each elements?

2
  • isn't there some sort of "intersection" function thing? Commented Feb 7, 2019 at 16:17
  • This fixed my problem. Thanks!! stackoverflow.com/questions/8317022/… Commented Feb 10, 2019 at 14:54

2 Answers 2

2

Use a list-comprehension:

A = [[1,2],[3,4],[5,6]]
B = [[5,6],[1,4],[6,5],[1,2]]

print([x for x in A if x in B])
# [[1, 2], [5, 6]]
Sign up to request clarification or add additional context in comments.

Comments

-1
A = [[1,2],[3,4],[5,6]]
B = [[5,6],[1,4],[6,5],[1,2]]

print([x for x in A if x in B])

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.