Re: [Numpy-discussion] Strange behavior of operator *=

2011-04-05 Thread Charles R Harris
On Tue, Apr 5, 2011 at 8:44 AM, Alan G Isaac wrote: > On 4/5/2011 10:37 AM, Nathaniel Smith wrote: > > Yes, this is a fact about Python 'int', not a fact about numpy -- a > > Python 'int' is defined to hold a C 'long', which will be either 32 or > > 64 bits depending on platform. > > > So what is

Re: [Numpy-discussion] Strange behavior of operator *=

2011-04-05 Thread Alan G Isaac
On 4/5/2011 10:37 AM, Nathaniel Smith wrote: > Yes, this is a fact about Python 'int', not a fact about numpy -- a > Python 'int' is defined to hold a C 'long', which will be either 32 or > 64 bits depending on platform. So what is the rule for Python 3, where iiuc it can no longer be "a fact abo

Re: [Numpy-discussion] Strange behavior of operator *=

2011-04-05 Thread Nathaniel Smith
On Tue, Apr 5, 2011 at 6:39 AM, Alan G Isaac wrote: > On 4/5/2011 9:26 AM, François Steinmetz wrote: >> It does not change the dtype, 'int' is just interpreted as 'int64' : > > So the meaning of 'int' is system specific? > >     >>> import numpy as np; a=np.eye(2,dtype='int'); a.dtype >     dtype(

Re: [Numpy-discussion] Strange behavior of operator *=

2011-04-05 Thread Paul Anton Letnes
On 5. apr. 2011, at 15.39, Alan G Isaac wrote: > On 4/5/2011 9:26 AM, François Steinmetz wrote: >> It does not change the dtype, 'int' is just interpreted as 'int64' : > > > So the meaning of 'int' is system specific? > import numpy as np; a=np.eye(2,dtype='int'); a.dtype > dtype('int

Re: [Numpy-discussion] Strange behavior of operator *=

2011-04-05 Thread Alan G Isaac
On 4/5/2011 9:26 AM, François Steinmetz wrote: > It does not change the dtype, 'int' is just interpreted as 'int64' : So the meaning of 'int' is system specific? >>> import numpy as np; a=np.eye(2,dtype='int'); a.dtype dtype('int32') Alan Isaac ___

Re: [Numpy-discussion] Strange behavior of operator *=

2011-04-05 Thread Friedrich Romstedt
2011/4/5 Alan G Isaac : > 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 exact

Re: [Numpy-discussion] Strange behavior of operator *=

2011-04-05 Thread Alan G Isaac
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... Alan Isaac ___

Re: [Numpy-discussion] Strange behavior of operator *=

2011-04-05 Thread François Steinmetz
Ok, thanks for the clarification ! François On Tue, Apr 5, 2011 at 11:55, Matthieu Brucher 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

Re: [Numpy-discussion] Strange behavior of operator *=

2011-04-05 Thread Matthieu Brucher
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. M

[Numpy-discussion] Strange behavior of operator *=

2011-04-05 Thread François Steinmetz
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,