I am running the exact same code on both windows and mac, with python 3.5 64 bit.
On windows, it looks like this:
JavaScript
x
9
1
>>> import numpy as np
2
>>> preds = np.zeros((1, 3), dtype=int)
3
>>> p = [6802256107, 5017549029, 3745804973]
4
>>> preds[0] = p
5
Traceback (most recent call last):
6
File "<pyshell#13>", line 1, in <module>
7
preds[0] = p
8
OverflowError: Python int too large to convert to C long
9
However, this code works fine on my mac. Could anyone help explain why or give a solution for the code on windows? Thanks so much!
Advertisement
Answer
You’ll get that error once your numbers are greater than sys.maxsize
:
JavaScript
1
8
1
>>> p = [sys.maxsize]
2
>>> preds[0] = p
3
>>> p = [sys.maxsize+1]
4
>>> preds[0] = p
5
Traceback (most recent call last):
6
File "<stdin>", line 1, in <module>
7
OverflowError: Python int too large to convert to C long
8
You can confirm this by checking:
JavaScript
1
4
1
>>> import sys
2
>>> sys.maxsize
3
2147483647
4
To take numbers with larger precision, don’t pass an int type which uses a bounded C integer behind the scenes. Use the default float:
JavaScript
1
2
1
>>> preds = np.zeros((1, 3))
2