Hi,
thanks for the answer, but I guess my request was not clear.
What I want is something which works in ALL cases so that

function(x, x1, x2) provides the output I mentioned... What you propose (as far as I can see) depends on the values of x1, x2, their order and the order of x (decreasing, increasing)...

if you have a hint on how to do this without TESTING how x is ordered (dec, inc) and which of x1 or x2 is larger...
thanks

Eric

Greg Willden wrote:
Hi Eric,
Here are ways of doing this.
starting with
import numpy as N

On 12/28/06, Eric Emsellem < [EMAIL PROTECTED]> 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.

_______________________________________________ Numpy-discussion mailing list [email protected] http://projects.scipy.org/mailman/listinfo/numpy-discussion

-- 
====================================================================
Eric Emsellem                             [EMAIL PROTECTED]
                           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
====================================================================


_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to