[Numpy-discussion] Strange behavior of operator *=

Friedrich Romstedt friedrichromstedt at gmail.com
Tue Apr 5 09:36:48 EDT 2011


2011/4/5 Alan G Isaac <alan.isaac at gmail.com>:
> On 4/5/2011 5:49 AM, François Steinmetz wrote:
>>  >>> a = eye(2, dtype='int')
>>  >>> a *= 1.0
>>  >>> a ; a.dtype
>> array([[1, 0],
>>         [0, 1]])
>> dtype('int64')
>
> This in-place (!) multiplication should not change
> the dtype of a.  I suspect you did not exactly cut
> and paste...

Guess he's on a 64 bit system.

$ # 32 bit
$ python2.6
Python 2.6.5 (r265:79063, Jul 18 2010, 12:14:53)
[GCC 4.2.1 (Apple Inc. build 5659)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> a = numpy.ones(1, dtype='int')
>>> a.dtype
dtype('int32')
>>> ^D

$ python2.6-64
Python 2.6.5 (r265:79063, Jul 18 2010, 12:14:53)
[GCC 4.2.1 (Apple Inc. build 5659)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> a = numpy.ones(1, dtype='int')
>>> a.dtype
dtype('int64')

This is with 1.4.1 (sorry for the missing update).

Same behaviour with numpy-1.5.1 on py2.7.

Friedrich



More information about the NumPy-Discussion mailing list