Int32s, scalar operations and Pyhon longs

Christopher Barker Chris.Barker at
Thu Nov 9 12:34:35 CST 2006

Robert Kern wrote:

> I think we decided long ago that an int32 really is an array of 32-bit integers
> and behaves like one.

That would apply to y*y:

 >>> x = 999999
 >>> y = numpy.array([x])
 >>> x*x

So Python ints automatically convert to Python longs on overflow.

 >>> y*y

numpy int32 arrays wrap...

 >>> z = y[0]
 >>> type(z)
<type 'numpy.int32'>
 >>> z*z
Warning: overflow encountered in long_scalars

int32 scalars wrap, but give a warning -- (why the warning here, but not 
with the array calculation?)

I'm a bit confused, because I thought that when you extracted a scalar 
from an array, you got regular python scalar for the datatypes that are 
supported. This made it clear that you always get a numpy Scalar, which, 
in a few situations, behaves differently than a seemingly equivalent 
Python scalar.

Have I got that right?


Christopher Barker, Ph.D.
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo

More information about the Numpy-discussion mailing list