Tagged Questions
0
votes
1answer
26 views
Overflow Error When Diving Large Numbers In Python
I am trying to use a code to look for Wilson Primes for a bit of fun and to get me back into the swing of coding, however, I found that when I try to divide 172! +1 By 173 it gives me an Overflow ...
2
votes
0answers
32 views
numpy memmap read error memory mapped size must be positive
I am reading a large binary file in partitions.
Each partition is mapped using numpy.memmap.
The file consist of 1M rows, where a row is 198 2-byte integers.
A partition is 1000 rows long.
Below ...
0
votes
1answer
513 views
Will an integer overflow in Python? [duplicate]
In languages such as Java, the integer value will overflow once it is larger than Integer.MAX_VALUE or when it is less than Integer.MIN_VALUE. I have seen posts where using a Long datatype was ...
1
vote
1answer
111 views
python Timedelta overflow
I am trying to return a timedelta but when time_value is too large it overflows and gives an error. I can use a check to see if time_value is too large but I would prefer a wrapper that handles the ...
1
vote
1answer
35 views
Integeroverflow when trying large values - factorization algorithm
I tried to implement Fermat's factorization method (see https://en.wikipedia.org/wiki/Fermat%27s_factorization_method), here's the code:
import math
def is_square(apositiveint):
x = apositiveint // ...
0
votes
1answer
208 views
Python float overflow, what happens when float overflows?
I was looking at the output from the code below. When I increment 1 to the maximum value of float, the output seems to be what I would expect, but when I do x=x*1.5, then I see inf as the output which ...
0
votes
0answers
126 views
Python math exp overflow error
As the title suggests, I get an overflow error when I am using math.exp(). As I am pretty novice and new to programming I would like a little help. I looked for an answer online but I couldn't figure ...
1
vote
2answers
47 views
How to handle number overflow?
I am calculating a trend line slope using numpy:
xs = []
ys = []
my_x = 0
for i in range(2000):
my_x += 1
ys.append(5*my_x+random.rand())
xs.append(my_x)
A = matrix(xs).T;
b = matrix(ys)....
3
votes
2answers
167 views
Python : overflow while subtraction
import cv2
image1 = cv2.imread('one.jpg', 0)
image2 = cv2.imread('two.jpg', 0)
diff = image1 - image2
For the above code, for some values, overflow due to subtraction is taking place.
For eg:
238 -...
8
votes
1answer
161 views
Get numpy to warn on integer overflow
Having mostly used python, I've gotten spoiled by not having to worry about integer overflow. Now that I'm using numpy, I have to worry about it again. I would like numpy to error in cases of ...
3
votes
1answer
90 views
Convert a very large base n number to bytes
I have a very large number in base n (n is specified by user), stored as an array with each element representing a digit. u[0] is the highest digit, u[1] is the second highest, u[-1] is the lowest ...
1
vote
2answers
96 views
Efficient element-wise multiplication in Python with numpy array
I have a numpy array of type np.int64, to which I am trying to apply a formula.
Let's say the array is a 2D array called total_img which has dimensions 400 X 300 pixels. For each pixel I want to ...
8
votes
1answer
121 views
Do numerical programming languages distinguish between a “largest finite number” and “infinity”?
Question motivation:
In standard numerical languages of which I am aware (e.g. Matlab, Python numpy, etc.), if, for example, you take the exponential of a modestly large number, the output is ...
9
votes
5answers
1k views
Avoid overflow when adding numpy arrays
I want to add numpy arrays with datatyp uint8. I know that the values in these arrays may be large enough for an overflow to happen. So I get something like:
a = np.array([100, 200, 250], dtype=np....
1
vote
1answer
55 views
Maximum value of kernel statistics - python
Question: What is the maximum value of kernel statistic counters and how can I handle it in python code?
Context: I calculate some statistics based on kernel statistics (e.g. /proc/partitions - it'll ...
0
votes
1answer
200 views
Getting number of rows larger than MAX_INT from cursor in Python's psycopg2 with Amazon Redshift
I have started using the Python module psycopg2 recently to work with a Redshift database.
I have a certain query which inserts a lot of rows (about 100 Billions), and the results of the cursor do ...
0
votes
3answers
125 views
How to avoid overflow in python when numerator and denominator are both large
from operator import mul
from fractions import Fraction
import math
n = 5000
def nCk(n,k):
return int( reduce(mul, (Fraction(n-i, i+1) for i in range(k)), 1) )
p = 2.884e-5
totP = 0
sgn = 1
...
0
votes
4answers
1k views
Python prevent overflow errors while handling large floating point numbers and integers
I am working on a python program to calculate numbers in the Fibonacci sequence. Here is my code:
import math
def F(n):
return ((1+math.sqrt(5))**n-(1-math.sqrt(5))**n)/(2**n*math.sqrt(5))
def ...
2
votes
1answer
86 views
Accurate Reflection of Size of Sum of Large Numbers with Integer Arithmetic
Thanks again for your time. I hope I didn't bug you guys too much.
When the sums overflows, but the mean is within range, how to get an accurate idea of the size of sum fast with integer arithmetic?
...
0
votes
2answers
135 views
How to fix a int overflow?
I'm having a python code that uses the number 2637268776 (bigger than sys.maxint in 32-bit systems). Therefore it is saved as a long type.
I'm using a C++ framework bindings in my code, so I have a ...
5
votes
4answers
4k views
Simulating integer overflow in Python
Python 2 has two integer datatypes int and long, and automatically converts between them as necessary, especially in order to avoid integer overflow.
I am simulating a C function in Python and am ...