[Numpy-discussion] TypeError in dtype.__eq__()
Sun Jan 11 15:13:24 CST 2009
> > However, also note
> > that with ndarray's rich comparisons, such membership testing will
> > fail with ndarrays, too.
> This poses a similarly big problem. I can't understand this behaviour
OK, I can now. After equality testing each item, the result must be cast
to bool. This is where the truth-testing comes in.
Testing array membership in lists does work, just so long as there are
no numerical objects in the list. Any/only equality comparisons which
return another (bool) ndarray will cause the exception. Thus, the error
is not triggered in PyYAML.
FWIW, I don't like the policy of forbidding truth testing on bare
arrays. I'd prefer that ndarray.__nonzero__() implicitly call
ndarray.all(). For my use-cases, this is what I want >90% of the time.
Where any() is required, this must be made explicit. However, I
understand the logic behind raising an exception and presumably others
Ultimately, I'm forced to conclude that the idea that membership testing
should always succeed was bogus. Bummer.
More information about the Numpy-discussion