I'm doing a program where I optimize some values. Due to the equations, from time to time my values are NaN
My problem, some of the entries are NaN.
I would like to know if there is a test to check their logical validity so I can skip those values and retry.
So far I have tried checking for
a==np.nan, a==nan, b=a a==b
To no avail.
I hope you can help me
Thanks
The math. isnan() method checks whether a value is NaN (Not a Number), or not. This method returns True if the specified value is a NaN, otherwise it returns False.
We cannot use the regular comparison operator, == , to check for NaN. NaN is not equal to anything (not even itself!).
nan is NOT equal to nan nan == np. nan is False can trigger a reaction of confusion and frustration.
nan is always false in the output.
Using numpy,
import numpy as np
np.isnan(np.nan) # returns True
Since Python 2.6, you want to import math
and use math.isnan(a)
.
See http://docs.python.org/library/math.html#math.isnan
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With