# [Numpy-discussion] extracting values from an array

Eric Emsellem emsellem at obs.univ-lyon1.fr
Thu Dec 28 11:59:01 CST 2006

```looks ok, except that I don't want to sort out the output but keep the
right order depending on x0 and x1, so I have then to add the order I
wish for the output array, maybe with something like:

## init
x0 = -0.55
x1 = -0.1
min,max,step = 0., -1., -0.1
x=num.arange(min,max,step);

## getting the right output
xs=sort(array([x0,x1]))
x[(x >= xs[0]) & (x<=xs[1])][::num.sign(x1-x0)*num.sign(step)]

should work. I don't see a simpler way here...

thanks to get me on track!!!

Eric
Greg Willden wrote:
> Hi Eric,
> Well I think that you have the parts that you need.
> Perhaps something like is what you want.  Put x1 and x2 into an array
> and sort it then access it from the sorted array.
>
> x=N.arange(0.,-1.,-0.1);
> xs=sort(array([-0.1, -0.55]));
> sort(x[(x >= xs[0] )&(x<=xs[1])])
>
> returns:  [-0.5,-0.4,-0.3,-0.2,-0.1,]
>
> x=N.arange(0.,1.,0.1);
> xs=sort(array([0.1, 0.55]));
> sort(x[(x >= xs[0] )&(x<=xs[1])])
>
> returns: [ 0.1, 0.2, 0.3, 0.4, 0.5,]

--
====================================================================
Eric Emsellem                             emsellem at obs.univ-lyon1.fr
Centre de Recherche Astrophysique de Lyon
9 av. Charles-Andre                        tel: +33 (0)4 78 86 83 84
69561 Saint-Genis Laval Cedex              fax: +33 (0)4 78 86 83 86
France                    http://www-obs.univ-lyon1.fr/eric.emsellem
====================================================================

```