[Numpy-discussion] Should bool_ subclass int?

Alan G Isaac aisaac@american....
Mon Jul 9 17:48:52 CDT 2007


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 
   (but granted, I would usually go with Python is such cases) 
2. consistency with Boolean matrices 

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)
>>>





More information about the Numpy-discussion mailing list