Int32s, scalar operations and Pyhon longs

Christopher Barker Chris.Barker at noaa.gov
Thu Nov 9 13:34:35 EST 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
999998000001L

So Python ints automatically convert to Python longs on overflow.

 >>> y*y
array([-729379967])

numpy int32 arrays wrap...

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

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?

-Chris

-- 
Christopher Barker, Ph.D.
Oceanographer
                                     		
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 noaa.gov

-------------------------------------------------------------------------
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
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the NumPy-Discussion mailing list