[Numpy-discussion] conditionals not fully implemented?

Chris Burns cburns1 at swarthmore.edu
Mon Feb 2 15:57:02 CST 2004


Hello.

I've graduated from numeric to numarray and been enjoying all the nifty
features, but I'm puzzled by the following behaviour when using conditionals
in a function like nonzero():

>>> import numarray
>>> print numarray.__version__
0.8
>>> x = numarray.arange(10)
>>> numarray.nonzero(x < 5)
(array([0, 1, 2, 3, 4]),)

So far so good

>>> numarray.nonzero(x < 5 and x > 2)
(array([3, 4, 5, 6, 7, 8, 9]),)
>>> numarray.nonzero((x < 5 and x > 2))
(array([3, 4, 5, 6, 7, 8, 9]),)
>>> numarray.nonzero( 2 < x < 5 )
(array([0, 1, 2, 3, 4]),)
>>> numarray.nonzero( (x < 5) * (x > 2) )
(array([3, 4]),)

So, only this last construction let's me get what I want.  Am I doing something
wrong or is the use of 'and' and 'or' not implemented for conditionals?

Thanks.

Chris

-- 
Chris Burns
Visiting Assistant Professor
Dept. of physics and astronomy, Swarthmore College
cburns1 at swarthmore.edu      http://hven.swarthmore.edu/~burns





More information about the Numpy-discussion mailing list