[Numpy-discussion] comparison style

Chris Barker chrishbarker at home.net
Mon May 21 12:55:13 EDT 2001

Warren Focke wrote:
> ] >>> 2 <= arange(8)
> ] array([0, 0, 1, 1, 1, 1, 1, 1])
> but, as noted in the rich comparison PEP, they don't chain:

> x <= y and y < z
> and we don't get to overload "and" :-(.

Clearly that would be nice. Why wasn't "and" allowed to be overloaded
when the rest of rich comparisons was allowed?

> (x <= y) & (y < z)
> seems like it might be a semi-reasonable substitute, and is shorter and
> appeals more to my preferring-operators-over-functions eyes, than
> Numeric.logical_and(x <= y, y < z)

It looks fine to me as well.

> - Do our comparisons really and truly ALWAYS return 1 or 0, even with Infs
> and Nans and whatnot?

Good question. There was a lot of discussion here recently about what
level of support NumPy should give to NaNs an Inf. Personally, I'd like
to see a well integrated support for it, which would include comparisons
(though bitwise could still be a problem). Of course, I have neither the
time nor the knowledge to do it, so I'll just have to wait...

There has also been talk of a "logical" array type. Is that going to
happen? If so, it would be the obvious choice to be returned from a
comparison and we could make sure the bitwise & and | work with it. I
notice that currently (I'm running 2.0, so ignore me if this has
changed) comparisons return an array of python Integers which seems a
massive waste of space.
> - It's potentially misleading for readers of the code.

well, yes, unless we really do have a 1 bit logical array type.


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