Home > OS >  Remove the intersection of 2 arrays in a numpy array
Remove the intersection of 2 arrays in a numpy array

Time:02-23

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

? Thanks already !

CodePudding user response:

[i for i in new_array if i not in old_array]

CodePudding user response:

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]])
  • Related