Without converting Numpy arrays to sets, what is the approach to find the set difference of two Numpy arrays or lists?

0 votes

You can use the setdiff1d() function of Numpy that returns elements in array1 that are not in array2. Here is an example:

>>> import numpy as np

>>> a=np.array([11,12,13,14,15])

>>> b=np.array([14,15,16,17,18])

>>> np.setdiff1d(a, b)

array([11, 12, 13])

>>> np.setdiff1d(b, a)

array([16, 17, 18])