I’m looking for a way to check for NaN values in Cython code. At the moment, I’m using:
if value != value:
# value is NaN
else:
# value is not NaN
Is there a better way to do this? Is it possible to use a function like Numpy’s isnan?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Taken from http://groups.google.com/group/cython-users/msg/1315dd0606389416, you could do this:
Then you can just use
isnan(value).In newer versions of Cython, it is even easier: