This content originally appeared on CodeSource.io and was authored by Deven
In this article, you will learn how to solve Divide by zero encountered in double_scalars error in Python.
Let’s look at a code example that produces the same error.
import numpy as np
def k(x):
x = np. float_(x)
return 1. / (1. - x)
print ('k(1.) =', k(1.) )
output
<string>:5: RuntimeWarning: divide by zero encountered in double_scalars
k(1.) = inf
In order to solve Divide by zero encountered in double_scalars error in Python is by simply changing the value that does not confirm to the division specification like in the code snippet below:
import numpy as np
def k(x):
x = np. float_(x)
return 1. / (0. - x)
print ('k(1.) =', k(1.) )
Output
k(1.) = -1.0
The post Solved – Divide by zero encountered in double_scalars appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Deven
Deven | Sciencx (2021-03-11T04:37:16+00:00) Solved – Divide by zero encountered in double_scalars. Retrieved from https://www.scien.cx/2021/03/11/solved-divide-by-zero-encountered-in-double_scalars/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.