在Cython中检查nan [英] Checking for nan in Cython

查看:63
本文介绍了在Cython中检查nan的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种检查Cython代码中NaN值的方法。此刻,我正在使用:

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

是否有更好的方法?是否可以使用像Numpy的 isnan 这样的函数?

Is there a better way to do this? Is it possible to use a function like Numpy's isnan?

推荐答案

来自 http://groups.google.com/group/cython-users/msg/ 1315dd0606389416 ,您可以执行以下操作:

Taken from http://groups.google.com/group/cython-users/msg/1315dd0606389416, you could do this:

cdef extern from "math.h":
    bint isnan(double x)

然后,您可以使用 isnan(value)

在较新版本的Cython中,它甚至更容易:

In newer versions of Cython, it is even easier:

from libc.math cimport isnan

这篇关于在Cython中检查nan的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆