Quantcast
Viewing all articles
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 all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>