• Register
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 5 3
6,930 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:


9 7 4
38,600 points
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))


11 5 1
3,890 points

Related questions

0 votes
1 answer 147 views
Problem: I am very new to Java and trying to learn arrays in Java. I am trying to enter one int and the other long ex: 1 and 1000000000 and now I am trying to create the array of size 1000000000. And after creating the array at each index of my array willing to store int val, ex: arr[ ... [1]);     long []arr;        arr = new long[y+1];         for(long j=0;j<=y;j++)         arr[j] = 4;     }
asked Jul 29 Raphael Pacheco 4.9k points
0 votes
1 answer 114 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 482 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 26 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 6.1k points
0 votes
1 answer 44 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