numpy.where

Neil Crighton neilcrighton at gmail.com
Thu Apr 9 10:33:42 CEST 2009


heidi taynton <heidihannah <at> mac.com> writes:

> 
> Hi,  
> 
> I'm fairly new to programming and am having a probably cutting my arrays.  I
have two different 1d arrays, one
> of time, and the second energy.    I want to cut both arrays of time 
min<=time<=max  .   I've created a 2d array
> with [time,energy] and I believe numpy.where is what I am looking for, but
haven't been able to get the
> conditions in right for it to work.  


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




More information about the Python-list mailing list