译(四十二)-Python判断NaN值
如有翻译问题欢迎评论指出,谢谢。
如何确定值是否为NaN?
Jack Ha asked:
float('nan')的输出是 NaN 而不是一个数。应该如何确定它到底是什么?感觉是个很简单的问题,但我不知道如何解决。
Answers:
gimel - vote: 1715
如果 x 为 NaN 而非一个数,将返回
True,否则将返回False。>>> import math >>> x = float('nan') >>> math.isnan(x) TrueChris Jester-Young - vote: 483
通常是通过判断它是否与自己相等来测试它是否是 NaN:
def isNaN(num): return num != nummavnn - vote: 224
numpy.isnan(number)可以判断是否为NaN。
How can I check for NaN values?
Jack Ha asked:
float('nan')results in Nan (not a number). But how do I check for it? Should be very easy, but I cannot find it.
float('nan')的输出是 NaN 而不是一个数。应该如何确定它到底是什么?感觉是个很简单的问题,但我不知道如何解决。
Answers:
gimel - vote: 1715
Return
Trueif x is a NaN (not a number), andFalseotherwise.
如果 x 为 NaN 而非一个数,将返回True,否则将返回False。>>> import math >>> x = float('nan') >>> math.isnan(x) TrueChris Jester-Young - vote: 483
The usual way to test for a NaN is to see if it\'s equal to itself:
通常是通过判断它是否与自己相等来测试它是否是 NaN:def isNaN(num): return num != nummavnn - vote: 224
numpy.isnan(number)tells you if it\'sNaNor not.
numpy.isnan(number)可以判断是否为NaN。


共有 0 条评论