Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I was executing the same code on both windows and mac, with python 3.5 64 bit version:

On my windows os, the code looks like:

>>> 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

But, the same code is working fine on my mac os. Kindly help!

1 Answer

0 votes
by (108k points)

I think you are getting this kind of error message because your numbers are greater than sys.maxsize:

>>> p = [sys.maxsize]

>>> preds[0] = p

>>> p = [sys.maxsize+1]

>>> preds[0] = p

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

OverflowError: Python int too large to convert to C long

You can check this with the below code:

>>> import sys

>>> sys.maxsize

2147483647

To execute the numbers with larger precision, I would suggest you to do not pass any int type which uses as bounded C integer behind the scenes. Use the default float:

>>> preds = np.zeros((1, 3))

For more information, kindly refer to the Python course.

Browse Categories

...