[SciPy-User] Select rows according to cell value

Oleksandr Huziy guziy.sasha@gmail....
Tue Nov 13 10:38:45 CST 2012


I am not sure if this way is easier thsn yours, but here is what I wpuld do

tol = 0.01
all_alts = data[:,0]
print all_alts
all_alts_temp = np.vstack([all_alts]*len(altitudes))
print all_alts_temp

sel_alts_temp = np.vstack([altitudes]*len(all_alts)).transpose()
print sel_alts_temp
sel_pattern = np.any( np.abs(all_alts_temp - sel_alts_temp) < tol, axis = 0)
print sel_pattern
print data
print data[sel_pattern,:]


Cheers
--
Oleksandr (Sasha) Huziy



2012/11/13 Andreas Hilboll <lists@hilboll.de>

> Am Di 13 Nov 2012 17:07:19 CET schrieb Juan Luis Cano Rodríguez:
> > 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.
> >
> >
> > _______________________________________________
> > SciPy-User mailing list
> > SciPy-User@scipy.org
> > http://mail.scipy.org/mailman/listinfo/scipy-user
>
> +1 for using pandas
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20121113/e62f85a5/attachment.html 


More information about the SciPy-User mailing list