Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python NumPy';s声称与NaN打交道_Python_Numpy - Fatal编程技术网

Python NumPy';s声称与NaN打交道

Python NumPy';s声称与NaN打交道,python,numpy,Python,Numpy,一年前我在一个旧系统(Python2.7,我相信它是NUMPY1.6.1)上写的一段代码在运行时遇到了麻烦。 我内置了很多“assert_array_几乎等于”来检查程序的运行。就我检查代码而言,我比较的是 >>> np.testing.assert_array_almost_equal([1.0,1.0,np.nan], np.ones(3)) 我不知道。这显然会引发断言错误。但是,由于代码在以前的系

一年前我在一个旧系统(Python2.7,我相信它是NUMPY1.6.1)上写的一段代码在运行时遇到了麻烦。 我内置了很多“assert_array_几乎等于”来检查程序的运行。就我检查代码而言,我比较的是

>>> np.testing.assert_array_almost_equal([1.0,1.0,np.nan],
                                     np.ones(3))

我不知道。这显然会引发断言错误。但是,由于代码在以前的系统上运行良好,我想知道“assert_array_几乎等于”中是否有更改,它以前只是忽略了NaNs。

我不相信有任何更改会导致您描述的行为。Numpy 1.6.0和1.7.0中的文档显示了相同的行为:

>>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan],
...                                      [1.0,2.33333, 5], decimal=5)
<type 'exceptions.ValueError'>:
ValueError:
Arrays are not almost equal
 x: array([ 1.     ,  2.33333,      NaN])
 y: array([ 1.     ,  2.33333,  5.     ])
>>np.testing.断言数组几乎相等([1.0,2.33333,np.nan],
…[1.0,2.33333,5],十进制=5)
:
值错误:
数组不是几乎相等的
x:数组([1,2.33333,NaN])
y:数组([1,2.33333,5.]))