• Register
Log In
0 votes

Problem :

While I am running the python code on windows with python 3.5 64 bit. Getting below error.

 overflowerror: python int too large to convert to c long

6.9k points

2 Answers

0 votes

Solution :

The issue is because the 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

Please confirm this by checking:

>>> import sys >>> sys.maxsize 

To resolve the issue use the default float:

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

Further Readings:


36.1k points
edited by
0 votes

In python 2, a Python int is equivalent to a C long data type. In python 3 an int is an arbitrary precision type but the numpy can still use it to represent the C type “long” while creating the array.


The size of a C long is platform dependent. On the Windows operating system it is always 32 bits. On Linux operating systems it behaves as 32 bits on 32 bits systems and 64 bits on 64 bits systems.


So it is suggested that choose a platform-independent data type. Probably this would be the most sensible choice in np.int64.


For example, you are getting this error when 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>”, lin1, in <module>

OverflowError: Python int too large to convert to C long


You can confirm this by using the following code;

>>> import sys

>>> sys.maxsize



To use the numbers with large precision, never use an int type which uses a bounded C integer behind the scenes. For this purpose use the default float value;

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


3.9k points

Related questions

0 votes
1 answer 70 views
Problem : Every time I submitted Python code, I got "invalid literal for int() with base 10:"
asked Oct 22, 2019 peterlaw 6.9k points
0 votes
2 answers 198 views
Problem : I am facing the below error in my program saying: Lyrics.java:11: error: cannot find symbol  Cube(b); ^ symbol: method Cube(int) location: class Lyrics Lyrics.java:15: error: incompatible types: possible lossy conversion from double to int  return Math.pow ... unable to understand the above error saying cannot find symbol. Please help me I am really been stuck on this error for a while.
asked Jan 14 jwilliam 3.9k points
1 vote
1 answer 14 views
Problem: I am beginner in pyhton prgramming language, I tried to convert string array to int array using python so I wrote a code which contains- testing_list = ['4', '2', '3', '9', '5'] And my code is: testing_list = ['4', '2', '3', '9', '5 ... list is : str(testing_list) Converted list is : str(testing_list) why am I not getting the converted result and what is the way to get the acurate result?
asked Mar 29 LizzyM 5.7k points
0 votes
1 answer 17 views
I start programming recently and I love to do programming but every day I'm facing new problems. I wrote a java code where I can easily take two int input from a user and I'm able to print the smallest value. But I'm doing all things in the main method. I don't want to do ... smallest; if(a>b){ smallest = b; }else{ smallest = a; } System.out.println("Smallest is: "+smallest); } Here is my code.
asked May 3 samhaz 5k points
0 votes
2 answers 152 views
Problem : I am new to RandomForest model. While predicting my test data using the RandomForest model I am often facing below ValueError. &ldquo;Input contains nan, infinity or a value too large for dtype('float64')&rdquo; I have spent more than two days on the above error but I am unable to fix above error. Can somebody help me in fixing above error?
asked Feb 24 mphil 2.3k points