[Numpy-discussion] Rich Comparisons and the Docs

Chris Barker chrishbarker at home.net
Fri Jun 1 18:17:51 EDT 2001

"Paul F. Dubois" wrote:
> The doc source is not available. I try to keep it up to date. If you would
> tell me the section I overlooked I will fix it.

That would be: Special Topics: Comparisons

> As to logical and and or, they are not available for overload in the rich
> comparisons schema. That's a Python decision.

I figured as much. I just took a look at PEP 207: Rich Comparisons, and
interestingly enough, the orignal version by David Asher addressed this
issue (at least in terms of chaining comparisons, such as a > b >c). In
the final PEP, I foound this:

    5 In the current proposal, when A<B returns an array of
      elementwise comparisons, this outcome is considered non-Boolean,
      and its interpretation as Boolean by the shortcut operators
      raises an exception.  David Ascher's proposal tries to deal
      with this; I don't think this is worth the additional complexity
      in the code generator.  Instead of A<B<C, you can write

I'm curious about the statement "I don't think this is worth the
additional complexity". It seems like being able to override the boolean
operators would be VERY useful, and it seems odd how quickly this was
glossed over. It is extremely common to combine a boolean operator with
a a comparison. Is it time for a "rich boolean operators" PEP, or was
this really rejected for good reason?

By the way, it doesn't seem to raise an exception for me, but it does
give a wrong (uninuitive anyway)answer:

>>> a = array([1,2,3])
>>> b = array([3,2,1])
>>> c = array([3,3,3])
>>> a < b < c
array([0, 1, 1])

Also, does (A<B)&(B<C) always work? Is this a reliable solution? What do
the bitwise operators do with Numeric arrays?

I guess the final question here is:

Is it time for a "rich boolean operators" PEP, or was this really
rejected for good reason?

Christopher Barker,
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------

More information about the NumPy-Discussion mailing list