Quantcast
Viewing latest article 1
Browse Latest Browse All 3

Answer by Alex Riley for NumPy: filter rows by np.array

Instead of using in, you can use np.in1d to check which values in the first column of ar are also in another_ar and then use the boolean index returned to fetch the rows of ar:

>>> ar[np.in1d(ar[:,0], another_ar)]array([[  1,   2],       [  6, -15]])

This is likely to be much faster than using any kind of for loop and testing membership with in.


Viewing latest article 1
Browse Latest Browse All 3

Trending Articles