[Numpy-discussion] filtering rows from a numpy.ndarray

Jan Wuyts jan.wuyts at gmail.com
Tue May 24 05:41:28 EDT 2011


I've read in a datafile to an ndarray with this command:

   data=np.genfromtxt('n.txt', delimiter='\t', dtype=[('paramname','S26'),
('study','S26'), ('class','S10'), ('count','f4'), ('average','f4'),
('sd','f4'))


I would like to filter the array to only rows where paramname == 'bmi'. What
would be the most elegant way of doing this? I found 1 way for doing this
but it doesn't look very efficient nor elegant.


   bmidata=np.asarray([x for x in data if x['paramname']=='bmi'],
dtype=data.dtype)


any simpler ways?


Thanks,


Jan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110524/17a5682e/attachment.html>


More information about the NumPy-Discussion mailing list