[Numpy-discussion] *= operator not intuitive
Charles R Harris
Wed Mar 16 08:34:16 CDT 2011
On Wed, Mar 16, 2011 at 7:24 AM, Paul Anton Letnes <
> This little snippet of code tricked me (in a more convoluted form). The *=
> operator does not change the datatype of the left hand side array. Is this
> intentional? It did fool me and throw my results quite a bit off. I always
> assumed that 'a *= b' means exactly the same as 'a = a * b' but this is
> clearly not the case!
Yes, it is intentional. Numpy is more C than Python in this case, it
actually does the multiplication in-place so that the result must have the
same type as the left hand side. In this case Python just creates a new
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion