[SciPy-User] Select rows according to cell value
Juan Luis Cano Rodríguez
juanlu001 at gmail.com
Tue Nov 13 11:07:19 EST 2012
I am loading some tabular data of the form
alt temp press dens
10.0 223.3 26500 0.414
10.5 220.0 24540 0.389
11.0 216.8 22700 0.365
11.5 216.7 20985 0.337
12.0 216.7 19399 0.312
12.5 216.7 17934 0.288
13.0 216.7 16579 0.267
13.5 216.7 15328 0.246
14.0 216.7 14170 0.228
into an ordinary NumPy array using np.loadtxt. I would like though to
select the rows according to the altitude level, that is:
>>> data = np.loadtxt('data.txt', skiprows=1)
>>> altitudes = [10.5, 11.5, 14.0]
>>> d = ... # some simple syntax involving data and altitudes
>>> d
10.5 220.0 24540 0.389
11.5 216.7 20985 0.337
14.0 216.7 14170 0.228
I have tried a cumbersome expression which traverses all the array, then
uses a list comprehension, converts to an array... but I'm sure there must
be a simpler way. I've also looked at argwhere. Or maybe I should use
pandas?
Thank you in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20121113/c26585a7/attachment.html>
More information about the SciPy-User
mailing list