This content originally appeared on CodeSource.io and was authored by Deven
In this article, you will learn how to solve overflow encountered in long_scalars error in Python.
Let’s look at a code example that produces the same error.
import numpy as np
np.seterr(all='warn')
B = np.array([144],dtype='double')
b=B[-1]
print ("Hello python:", b**b)
Output
/tmp/sessions/5e568ca1c8f93f65/main.py:9: RuntimeWarning: overflow encountered in double_scalars
print ("Hello python:", b**b)
In order to solve overflow encountered in long_scalars error in Python you need choose appropriate dtypes
so that no operation overflows as shown in the code snippet below:
import numpy as np
np.seterr(all='warn')
B = np.array([143],dtype='double')
b=B[-1]
print ("Hello python:", b**b)
Output
Hello python: 1.6332525972973913e+308
please note that the maximum value storable in an int32
is 2**31-1.
The post Solved – overflow encountered in long_scalars appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Deven
Deven | Sciencx (2021-03-11T07:25:34+00:00) Solved – overflow encountered in long_scalars. Retrieved from https://www.scien.cx/2021/03/11/solved-overflow-encountered-in-long_scalars/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.