logical statements (in Python and Numeric)

Fernando Pérez fperez528 at yahoo.com
Thu Jun 20 21:43:48 CEST 2002


Chris Barker wrote:

> One solution is to use the bitwise operators instead:
> y = y + (x >= -2. & x < 0.) * (x + 6.)
> 

Are you sure? This is what I get:

In [11]: x = arrayrange(-4.,2.+.001,.001, Float)

In [12]: x >= -2. & x < 0.
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

?

TypeError: unsupported operand type(s) for &: 'float' and 'float'


That's why I suggested logical_and() as a workaround. But maybe I'm missing 
something.

Cheers,

f.



More information about the Python-list mailing list