[Numpy-discussion] where construct

Hans Meine meine@informatik.uni-hamburg...
Thu Dec 20 06:42:53 CST 2007


Am Sonntag, 16. Dezember 2007 20:10:41 schrieb Ross Harder:
> What's the correct way to do something like this?
>
> a=array( (0,1,1,0) )
> b=array( (4,3,2,1) )
> c=array( (1,2,3,4) )
>
> where( (a<1 or b<3), b,c)

Now + and | have been proposed to you, but it looks to me as if the "correct 
way" would be logical_or.  All solutions give the same result, but logical_or 
better expresses what you're trying to do:

In [9]: print where( (logical_or(a<1, b<3)), b,c)
[4 2 2 1]

(Think of the Zen.)

Ciao, /  /
     /--/
    /  / ANS


More information about the Numpy-discussion mailing list