[Numpy-discussion] Should bool_ subclass int?
Timothy Hochberg
tim.hochberg@ieee....
Mon Jul 9 18:24:44 CDT 2007
On 7/9/07, Alan G Isaac <aisaac@american.edu> wrote:
>
> On Mon, 9 Jul 2007, Timothy Hochberg apparently wrote:
> > Why not simply use & and | instead of + and *?
>
> A couple reasons, none determinative.
> 1. numpy is right a Python is wrong it this case
I don't think I agree with this. Once you've decided to make Boolean a
subclass of Int, then Python's behavior seems to be the most sensible. One
could argue (and people did) about whether that was a good choice, but it's
useful for a lot of practical applications. In any event, given that Boolean
subclasses Int, I think the current behavior is probably for the best.
(but granted, I would usually go with Python is such cases)
> 2. consistency with Boolean matrices
OK. I sort of read past the fact that you were referring to matrices not
arrays. This doesn't matter to me personally because I don't use the matrix
class. I do do matrix algebra on occasion, but the matrix class has never
been helpful for me. YMMV.
Elaboration on 2:
> Boolean matrices currently behave as expected, with standard
> notation. Related to this, they handle exponents correctly.
>
> Suppose arrays are changed as you suggest.
> Then either
> - array behavior and matrix behavior are decoupled, or
> - matrix behavior is completely broken for boolen matrices
>
> Alan Isaac
>
> PS Examples of good behavior:
>
> >>> x
> matrix([[True, True],
> [True, False]], dtype=bool)
> >>> y
> matrix([[False, True],
> [True, False]], dtype=bool)
> >>> x*y
> matrix([[True, True],
> [False, True]], dtype=bool)
> >>> x**2
> matrix([[True, True],
> [True, True]], dtype=bool)
x*y and x**2 are already decoupled for arrays and matrices. What if x*y was
simply defined to do a boolean matrix multiply when the arguments are
boolean matrices?
I don't care about this that much though, so I'll let it drop.
--
. __
. |-\
.
. tim.hochberg@ieee.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070709/8a68e35e/attachment.html
More information about the Numpy-discussion
mailing list