Solved – Divide by zero encountered in double_scalars

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…

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

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


Print Share Comment Cite Upload Translate Updates
APA

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/

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

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