Discussion RoomCategory: PythonHow to remove from one array those items that exist in another?
Ram asked 3 years ago

 

Q. From array a remove all items present in array b
Input:

a = np.array([1,2,3,4,5])
b = np.array([5,6,7,8,9])

Desired Output:

array([1,2,3,4])

Show Solution

a = np.array([1,2,3,4,5])
b = np.array([5,6,7,8,9])

# From 'a' remove all of 'b'
np.setdiff1d(a,b)
#> array([1, 2, 3, 4])