[Numpy-discussion] extracting values from an array
Greg Willden
gregwillden at gmail.com
Thu Dec 28 10:31:44 CST 2006
Hi Eric,
Here are ways of doing this.
starting with
import numpy as N
On 12/28/06, Eric Emsellem <emsellem at obs.univ-lyon1.fr> wrote:
>
> ### Increasing order in x, and x1 <= x2 :
> x = arange(0.,1.,0.1)
> x1 = 0.1
> x2 = 0.55
> ### the output I would like is simply: array([ 0.1, 0.2, 0.3, 0.4,
> 0.5])
How about this?
x=N.arange(0.,1.,0.1)
x[ (x>=0.1) & (x<=0.55) ]
### decreasing order in x, and x1 <= x2 :
> x = arange(0.,-1.,-0.1)
> x1 = -0.55
> x2 = -0.1
> ### I would like is then: array([ -0.5, -0.4, -0.3, -0.2, -0.1])
x=N.arange(0.,-1.,-0.1)
N.sort( x[ (x<=-0.1) & (x>=-0.55) ] )
or
x[(x<=-0.1)&(x>=-0.55)][::-1]
just reverses the returned array.
### decreasing order in x, and x1 >= x2 :
> x = arange(0.,-1.,-0.1)
> x1 = -0.1
> x2 = -0.55
> ### I would like is then: array([ -0.1, -0.2, -0.3, -0.4, -0.5])
x=N.arange(0.,-1.,-0.1)
x[ (x<=-0.1) & (x>=-0.55) ]
A few comments because I'm not totally clear on what you want to do.
(x<=-0.1)&(x>=-0.55)
will give you a boolean array of the same length as x
find((x<=-0.1)&(x>=-0.55))
will return the list of indices where the argument is true.
Regards,
Greg
--
Linux. Because rebooting is for adding hardware.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20061228/bd2189be/attachment.html
More information about the Numpy-discussion
mailing list