[Numpy-discussion] Numeric/numarray compatibility issue

konrad.hinsen at laposte.net konrad.hinsen at laposte.net
Fri Mar 4 10:25:43 EST 2005


On 04.03.2005, at 16:44, Perry Greenfield wrote:

> First of all, isn't the current behavior a little similar to Python in  
> that Python Booleans aren't pure either (for backward compatibility  
> purposes)?

Possibly, but the use of boolean scalars and boolean arrays is very  
different, so that's not necessarily the model to follow.

> apparently many preferred avoiding automatic promotion (the reductions  
> allow specifying a new type for the reduction, but I don't believe  
> that helps your specific example for code that works for both). Using  
> .astype(Int32)

Right, because it doesn't work with Numeric.

>  should work for both, right? (or is that too much of a speed hit?)  
> But it is a

Yes, but it costs both time and memory.  I am more worried about the  
memory, since this is one of the few operations that I do mostly with  
big arrays. Under Numeric, this doubles memory use, costs time, and  
makes no difference for the result. I am not sure that numarray  
compatibility is worth that much for me (OK, there is a dose of  
laziness in that argument as well).

>  fair question to ask if arithmetic operations should be allowed on  
> booleans without explicit casts.
>
What is actually the difference between Bool and Int8?


On 04.03.2005, at 18:27, Stephen Walton wrote:

> It has.  I think I commented on it some time back, and the consensus  
> was that, as Perry suggested, using .astype(Int32) is the best fix.  I  
> think the fact that arithmetic is allowed on booleans without casts is  
> an oversight;  standard Python 2.3 allows you to do True+False.  
> Fortran would never let you do .TRUE.+.FALSE. :-) .

I am in fact not convinced that adding booleans to Python was a very  
good idea, for exactly that reason: they try to be both booleans and  
compatible with integers.

Konrad.
--
------------------------------------------------------------------------ 
-------
Konrad Hinsen
Laboratoire Leon Brillouin, CEA Saclay,
91191 Gif-sur-Yvette Cedex, France
Tel.: +33-1 69 08 79 25
Fax: +33-1 69 08 82 61
E-Mail: khinsen at cea.fr
------------------------------------------------------------------------ 
-------





More information about the NumPy-Discussion mailing list