[SciPy-dev] Arrays as truth values?

Ed Schofield schofield at ftw.at
Tue Nov 8 09:29:28 CST 2005



On Tue, 8 Nov 2005, Robert Kern wrote:
> Ed Schofield wrote:
>
> > Using == and != to compare arrays was simple and (I think) unambiguous
> > before. It would be nice to allow these comparisons again, while raising
> > an exception for the general case.  Perhaps we could modify arrays' __eq__
> > and __neq__ methods to call .any() and .all() for us, returning a single
> > truth value, rather than returning an array of truth values as it does
> > currently?
>
> In any case, you can't have those methods "call .any() and .all() for
> us;" there really is an ambiguity. We don't know beforehand which one
> you want called. And in the face of ambiguity, we're refusing the
> temptation to guess.

We've seen that there's an ambiguity in the case of logical operations on
arrays like "a and b", "a or b".  But I don't see any ambiguity in the
case of == and !=.  Can two arrays be considered 'equal' if any of their
elements differ? ;)

You're right that my code that now raises an exception was silently wrong
before.  That's a definite step forward.


> Any API compatibility with the stdlib's array module is entirely
> coincidental. It's not a goal and never will be.

Yes, it is a goal.  The recent conversion of typecodes for better
compatibility with 'array' and 'struct' is an example.  When there's no
good argument to differ we might as well be consistent with the standard
library.


-- Ed




More information about the Scipy-dev mailing list