Quantcast
Channel: NumPy: filter rows by np.array - Stack Overflow
Viewing all articles
Browse latest Browse all 3

NumPy: filter rows by np.array

$
0
0

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

Latest Images

Trending Articles





Latest Images