python – How can I check for NaN values?

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 its equal to itself:

def isNaN(num):
    return num != num

python – How can I check for NaN values?

numpy.isnan(number) tells you if its NaN or not.

Leave a Reply

Your email address will not be published.