numpy.setdiff1d#

numpy.setdiff1d(ar1,ar2,assume_unique=False)[source]#

Find the set difference of two arrays.

Return the unique values inar1 that are not inar2.

Parameters:
ar1array_like

Input array.

ar2array_like

Input comparison array.

assume_uniquebool

If True, the input arrays are both assumed to be unique, whichcan speed up the calculation. Default is False.

Returns:
setdiff1dndarray

1D array of values inar1 that are not inar2. The resultis sorted whenassume_unique=False, but otherwise only sortedif the input is sorted.

Examples

>>>importnumpyasnp>>>a=np.array([1,2,3,2,4,1])>>>b=np.array([3,4,5,6])>>>np.setdiff1d(a,b)array([1, 2])
On this page