Remove elements from one array if present in another array, keep duplicates - NumPy / Python
- 阅读更多 关于 Remove elements from one array if present in another array, keep duplicates - NumPy / Python
问题 I have two arrays A (len of 3.8million) and B (len of 20k). For the minimal example, lets take this case: A = np.array([1,1,2,3,3,3,4,5,6,7,8,8]) B = np.array([1,2,8]) Now I want the resulting array to be: C = np.array([3,3,3,4,5,6,7]) i.e. if any value in B is found in A , remove it from A , if not keep it. I would like to know if there is any way to do it without a for loop because it is a lengthy array and so it takes long time to loop. 回答1: Using searchsorted With sorted B , we can use