3

How do I find the difference between two 2D array in python ?

First array and second array

arr1 = [[1,1],[1,2],[1,3],[1,4],[1,5]]
arr2 = [[1,2],[1,3],[1,4]]

The result I want

result = [[1,1],[1,5]]
1

1 Answer 1

4

You can first convert all element to tuple then use set and difference like below:

>>> set(map(tuple,arr1)).difference(map(tuple,arr2))
{(1, 1), (1, 5)}

>>> list(map(list , set(map(tuple,arr1)).difference(map(tuple,arr2))))
[[1,1],[1,5]]
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.