[Numpy-discussion] Strange behavior of operator *=

François Steinmetz francois.steinmetz at gmail.com
Tue Apr 5 06:41:05 EDT 2011


Ok, thanks for the clarification !

François

On Tue, Apr 5, 2011 at 11:55, Matthieu Brucher
<matthieu.brucher at gmail.com>wrote:

> Indeed, it is not. In the first case, you keep your original object and
> each (integer) element is multiplied by 1.0. In the second example, you are
> creating a temporary object a*x, and as x is a float and a an array of
> integers, the result will be an array of floats, which will be assigned to
> a.
>
> Matthieu
>
> 2011/4/5 François Steinmetz <francois.steinmetz at gmail.com>
>
>> Hi all,
>>
>> I have encountered the following strangeness :
>> >>> from numpy import *
>> >>> __version__
>> '1.5.1'
>> >>> a = eye(2, dtype='int')
>> >>> a *= 1.0
>> >>> a ; a.dtype
>> array([[1, 0],
>>        [0, 1]])
>> dtype('int64')
>> >>> a = a * 1.0
>> >>> a ; a.dtype
>> array([[ 1.,  0.],
>>        [ 0.,  1.]])
>> dtype('float64')
>>
>> So, in this case "a *= x" is not equivalent to "a = a*x" ?
>>
>>  François
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>>
>
>
> --
> Information System Engineer, Ph.D.
> Blog: http://matt.eifelle.com
> LinkedIn: http://www.linkedin.com/in/matthieubrucher
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110405/aca06f42/attachment.html>


More information about the NumPy-Discussion mailing list