[Numpy-discussion] __iadd__(ndarray<int>, ndarray<float>)

Andreas Klöckner lists at informa.tiker.net
Tue Mar 25 08:57:58 EDT 2008


On Dienstag 25 März 2008, Nadav Horesh wrote:
> scalars are immutable objects in python. Thus the += (and alike) are "fake":

Again, thanks for the explanation. IMHO, whether or not they are fake is an 
implementation detail. You shouldn't have to know Python's guts to be able to 
use Numpy successfully. Even if they weren't fake, implementing my suggested 
semantics in Numpy wouldn't be particularly hard.

> [snip]
> a += 3 is really equivalent to a = a+3. 

Except when it isn't.

> [snip]
> numpy convention is consistent
> with the python's spirit.

A matter of taste.

> I really use that fact to write arr1 += 
> something, in order to be sure that the type of arr1 is conserved, and
> write arr1 = arr1+something, to allow upward type casting.

I'm not trying to make the operation itself go away. I'm trying to make the 
syntax beginner-safe. Complete loss of precision without warning is not a 
meaning that I, as a toolkit designer, would assign to an innocent-looking 
inplace operation. My hunch is that many people who start with Numpy will 
spend an hour of their lives hunting a spurious bug caused by this. I have. 
Think of the time we can save humanity. :)

Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20080325/e377acb4/attachment.sig>


More information about the NumPy-Discussion mailing list