
1 May
2007
1 May
'07
2:59 p.m.
OK...so just for future reference...does a Numpy 'long' not directly correspond to a Python 'long'?
Robert Kern wrote:
Mark.Miller wrote:
Can someone explain this? I can't seem to coerce numpy into storing large integer values. I'm sure that I'm just overlooking something simple...
import numpy a='1'*300 type(a)
<type 'str'>
b=int(a) type(b)
<type 'long'>
c=numpy.empty((2,2),long) c[:]=b
Traceback (most recent call last): File "<pyshell#15>", line 1, in <module> c[:]=b OverflowError: long too big to convert
Use object arrays explicitly:
c = numpy.empty((2, 2), dtype=object)
Using dtype=long gets interpreted as requesting the largest available integer type (or maybe just int64, I'm not sure). Those aren't unbounded.