'Remove the intersection of 2 arrays in a numpy array
I have 2 array:
old_array = [[1,2,3],[4,5,6],[7,8,9]]
new_array = [[10,11,12],[1,2,3],[4,5,6],[13,14,15]]
is there an easy algoritm to remove the rows who are already in old_array from new_array, so that the value of new_array is eventually
new_array = [[10,11,12],[13,14,15]]
Solution 1:[1]
You could use set differences:
>>> np.array(list(set(map(tuple, new_array)).difference(set(map(tuple, old_array)))))
array([[13, 14, 15],
[10, 11, 12]])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | not_speshal |
