【问题标题】:NaN in python and validity checking [duplicate]python中的NaN和有效性检查[重复]
【发布时间】:2011-08-26 09:10:02
【问题描述】:

我正在做一个优化一些值的程序。由于方程,有时我的值是 NaN

我的问题,有些条目是 NaN。

我想知道是否有测试来检查它们的逻辑有效性,以便我可以跳过这些值并重试。

到目前为止,我已经尝试过检查

a==np.nan, a==nan, b=a a==b

无济于事。

希望你能帮到我

谢谢

【问题讨论】:

    标签: python numpy nan


    【解决方案1】:

    使用 numpy,

    import numpy as np
    np.isnan(np.nan) # returns True
    

    【讨论】:

      【解决方案2】:

      从 Python 2.6 开始,您想要 import math 并使用 math.isnan(a)

      http://docs.python.org/library/math.html#math.isnan

      【讨论】:

      • 有什么理由要使用math 而不是numpy
      • 其实,我可能已经找到the answer 到我自己的问题:)
      猜你喜欢
      • 2014-08-17
      • 2011-03-14
      • 2011-03-27
      • 2020-05-13
      • 2015-03-26
      • 2023-03-15
      • 2020-06-25
      • 2015-02-23
      • 1970-01-01
      相关资源
      最近更新 更多