. Advertisement .
..3..
. Advertisement .
..4..
I get an error
>>> import numpy as np
>>> preds = np.zeros((1, 3), dtype=int)
>>> p = [6802256107, 5017549029, 3745804973]
>>> preds[0] = p
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
preds[0] = p
OverflowError: Python int too large to convert to C long
when trying to run the exact same code on both windows and mac(python 3.5 64 bit). How to fix the overflowerror: python int too large to convert to c long error? Please give me some advice.
The cause: You get this error because your numbers exceed
sys.maxsize
:To confirm this, you can check:
The solution: Don’t pass an int type that uses a bounded C integer behind the scenes if you want to take numbers with larger precision. Use the default float:
dtype=np.int64
can be used in place ofdtype=int
.