numpy.where
Lou Pecora
pecora at anvil.nrl.navy.mil
Thu Apr 9 09:09:18 EDT 2009
In article <mailman.3576.1239266409.11746.python-list at python.org>,
Neil Crighton <neilcrighton at gmail.com> wrote:
>
> I'm not sure exactly what you're trying to do, but maybe you want a boolean
> array to select the right elements? So if time and energy are 1-d numpy arrays
> of the same length:
>
> >>> condition = (min_time <= time) & (time <= max_time)
> >>> new_time = time[condition]
> >>> new_energy = energy[condition]
>
> There's also a Numpy list for these kind of questions:
>
> http://dir.gmane.org/gmane.comp.python.numeric.general
>
> Neil
Thanks, Neil. Always something to learn. I've used Numpy for several
years, but still have not plumbed the depths. Just tried this script
and, yep, it works.
arr=array([-1,1.0,2.2,-10.0,1.1, 0.9,-0.9])
cond= arr < 1.0
print cond
brr=arr[cond]
print brr
Output:
[ True False False True False True True]
[ -1. -10. 0.9 -0.9]
Really, I've gotta RTFM. :-)
--
-- Lou Pecora
More information about the Python-list
mailing list