How can I check for NaN values? How can I check for NaN values? python python

How can I check for NaN values?


math.isnan(x)

Return True if x is a NaN (not a number), and False otherwise.

>>> import math>>> x = float('nan')>>> math.isnan(x)True


The usual way to test for a NaN is to see if it's equal to itself:

def isNaN(num):    return num != num


numpy.isnan(number) tells you if it's NaN or not.