Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the causes of overflow encountered in double_scalars besides division by zero?

Tags:

python

numpy

I read about double scalar but just partly understand. From my understanding, it is the range that is available to calculate by Numpy. That's why most questions here focusing on the division by zero (which is an error because the answer will be out of range (infinity)).

But I am so unsure that my understanding is correct. Also, I can't see other causes about RuntimeWarning:overflow encountered in double_scalars. What can cause overflow encountered in double scalars?

like image 618
Jan Avatar asked Apr 14 '17 05:04

Jan


1 Answers

Overflow error implies that an operation yields a value out of the range defined for the corresponding data type. For numpy double, that range is (-1.79769313486e+308, 1.79769313486e+308). Also, for a good discussion, please read this SO post.

Example:

import numpy as np
np.seterr(all='warn')
print "Range of numpy double:", np.finfo(np.double).min, np.finfo(np.double).max
A = np.array([143],dtype='double')
a=A[-1]
print "At the border:", a**a
B = np.array([144],dtype='double')
b=B[-1]
print "Blowing out of range:", b**b

Output:

Range of numpy double: -1.79769313486e+308 1.79769313486e+308
At the border: 1.6332525973e+308 
Blowing out of range: inf
D:\anaconda\lib\site-packages\ipykernel\__main__.py:9: RuntimeWarning: overflow encountered in double_scalars
like image 86
devautor Avatar answered Oct 22 '22 01:10

devautor