[Numpy-discussion] *= operator not intuitive
Charles R Harris
charlesr.harris at gmail.com
Wed Mar 16 09:34:16 EDT 2011
On Wed, Mar 16, 2011 at 7:24 AM, Paul Anton Letnes <
paul.anton.letnes at gmail.com> wrote:
> Hi!
>
> 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
object.
<snip>
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110316/8b37bef8/attachment.html>
More information about the NumPy-Discussion
mailing list