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