Bio-Python

"Ramblings on computational chemistry, in silico experiments and programming in python 3.x"

February 26, 2013

Checking 'nan' and 'inf', pythonic way

How to check for Not a Number (NaN) or Infinity (Inf) in python?

NaN:

In python you can declare 'nan' as a float.

Inf:

When you try print(1E650), it returns inf. In python, variable x can be checked for 'inf' using math.isinf(x)

For more on 'nan' and 'inf' refer PEP 754.