0

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]]
Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
BGR
  • 137
  • 6
  • Does this answer your question? [Find the set difference between two large arrays (matrices) in Python](https://stackoverflow.com/questions/11903083/find-the-set-difference-between-two-large-arrays-matrices-in-python) – not_speshal Feb 22 '22 at 15:23

2 Answers2

2
[i for i in new_array if i not in old_array]
Darina
  • 1,488
  • 8
  • 17
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]])
not_speshal
  • 22,093
  • 2
  • 15
  • 30