[Numpy-discussion] Should bool_ subclass int?
Alan G Isaac
aisaac@american....
Tue Jul 10 09:36:55 CDT 2007
I found Gael's presentation rather puzzling for two reasons.
1. It appears to contain a `+` vs. `*` confusion.
See http://en.wikipedia.org/wiki/Two-element_Boolean_algebra
2. MUCH more importantly:
In implementations of TWO, we interpret `-` as unary
complementation (not e.g. as additive inverse; note True
does not have one). So
-True is False
-False is True
This matches numpy:
>>> -N.array([False])
array([True], dtype=bool)
>>> -N.array([True])
array([False], dtype=bool)
This is a GOOD THING.
However, a-b should then just be shorthand for a+(-b).
Here numpy does not in my opinion behave correctly:
>>> N.array([False])-N.array([True])
array([True], dtype=bool)
>>> N.array([False])+(-N.array([True]))
array([False], dtype=bool)
The second answer is the right one, in this context.
I would call this second answer a bug.
Cheers,
Alan Isaac
More information about the Numpy-discussion
mailing list