Quantcast
Viewing all articles
Browse latest Browse all 3

NumPy: filter rows by np.array

I'd like to filter a NumPy 2-d array by checking whether another array contains a column value. How can I do that?

import numpy as npar = np.array([[1,2],[3,-5],[6,-15],[10,7]])another_ar = np.array([1,6])new_ar = ar[ar[:,0] in another_ar]print new_ar

I hope to get [[1,2],[6,-15]] but above code prints just [1,2].


Viewing all articles
Browse latest Browse all 3

Trending Articles



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