Eric Firing wrote:
> Robert Kern wrote:
>> Eric Firing wrote:
>>
>>> It seems that the logical operators || and &&, corresponding to 
>>> logical_or and logical_and are missing; one can do
>>>
>>> z = logical_and(x,y)
>>>
>>> but not
>>>
>>> z = x && y
>>>
>>> Is there an inherent reason, or is this a bug?
>>
>> Python does not have a && operator. It has an "and" keyword, but that cannot 
>> be 
>> overridden. If you know x and y to be boolean arrays, & and | work fine.
> 
> Out of curiosity, is there a simple explanation as to why "and" cannot 
> be overridden but operators like "&" can?  Is it a fundamental 
> distinction between operators and keywords?

Sort of. "and" and "or" short-circuit, that is they stop evaluating as soon as 
the right value to return is unambiguous.

In [1]: def f():
    ...:     print "Shouldn't be here."
    ...:
    ...:

In [2]: False and f()
Out[2]: False

In [3]: True or f()
Out[3]: True

Consequently, they must yield True and False only.

> In any case, it sounds like we are indeed stuck with an unfortunate wart 
> on numpy, unless some changes in Python can be made.  Maybe for 
> Python3000...
> 
> The NumPy for Matlab users wiki is misleading in this area; I will try 
> to fix it.

Thank you.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Numpy-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Reply via email to