[Numpy-discussion] Should bool_ subclass int?
Tue Jul 10 07:39:28 CDT 2007
On 7/10/07, Matthieu Brucher <firstname.lastname@example.org> 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.
> If bool subclasses int, this does not enforce True+True=2. Never. Boolean
> operation live in the Boole algebra and that's it. It's not the case with
> integers that cannot be represented with int.
> Now, if you take the algebra point of view, which is the point here, for a
> scientific application, you have to have True+True = True.
When you talk about algebra - one might have to restrict one self to '|' and '&'
-- not use '+' and '-'
True - True = False # right !?
# but if:
True+True = True.
True+True -False = True -False # ????
# here I'm already lost ... I don't think this can be done in a consistent way.
In other words: a "+" operator would also need a corresponding "-"
operator, and that will just look funny. I think if you want algebra,
you should restrict yourself to "|" (or) and "&" (and)
My two cents,
More information about the Numpy-discussion