比较包含NaN的列表

比较包含NaN的列表,第1张

比较包含NaN的列表

要了解这里发生的情况,只需替换

nan = np.nan
foo = float('nan')
,您将得到完全相同的结果,为什么?

>>> foo = float('nan')>>> foo is foo # This is obviously True! True>>> foo == foo # This is False per the standard (nan != nan).False>>> bar = float('nan') # foo and bar are two different objects.>>> foo is barFalse>>> foo is float(foo) # "Tricky", but float(x) is x if type(x) == float.True

现在认为这

numpy.nan
只是一个包含
float('nan')
。的变量名。

现在为什么

[nan] == [nan]
仅仅是因为
list
比较首先要在项目之间进行身份平等性的检验,然后才是价值相等,所以将其视为

def equals(l1, l2):    for u, v in zip(l1, l2):        if u is not v and u != v: return False    return True


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5648439.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存