Solved – overflow encountered in long_scalars

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….

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

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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Solved – overflow encountered in long_scalars." Deven | Sciencx - Thursday March 11, 2021, https://www.scien.cx/2021/03/11/solved-overflow-encountered-in-long_scalars/
HARVARD
Deven | Sciencx Thursday March 11, 2021 » Solved – overflow encountered in long_scalars., viewed ,<https://www.scien.cx/2021/03/11/solved-overflow-encountered-in-long_scalars/>
VANCOUVER
Deven | Sciencx - » Solved – overflow encountered in long_scalars. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/11/solved-overflow-encountered-in-long_scalars/
CHICAGO
" » Solved – overflow encountered in long_scalars." Deven | Sciencx - Accessed . https://www.scien.cx/2021/03/11/solved-overflow-encountered-in-long_scalars/
IEEE
" » Solved – overflow encountered in long_scalars." Deven | Sciencx [Online]. Available: https://www.scien.cx/2021/03/11/solved-overflow-encountered-in-long_scalars/. [Accessed: ]
rf:citation
» Solved – overflow encountered in long_scalars | Deven | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.