【发布时间】:2019-10-31 20:45:42
【问题描述】:
正如this question 中显示的那样,从 numpy 中使用 nan 如何导致 dict 出现问题,为什么 math.nan 的行为会有所不同? (Python3)
import math
import numpy as np
d = {math.nan:'baz', math.nan:'bip' }
print(d)
e = {np.float('nan'):'foo', np.float('nan'):'bar' }
print(e)
输出
{nan: 'bip'}
{nan: 'foo', nan: 'bar'}
【问题讨论】:
-
此外,以下两个都是真的:
math.nan is math.nannp.float('nan') is not np.float('nan') -
事实上,在很多平台上,
np.float is float。 -
@wim:在
numpy是官方发行版的每个平台上