From: Christopher B. <Chr...@no...> - 2006-11-09 21:39:53
|
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 Chr...@no... |