在我的python測試腳本中,我想斷言numpy數組的所有元素是非常接近於1.0還是等於0.0。該陣列是這樣的:檢查numpy數組中的所有元素是否匹配
[[0.9999999991268851 1.0000000223517418 0.999999986961484 ...,
0.9999999841675162 1.0000000074505806 0.9999999841675162]
[0.9999999991268851 1.0000000223517418 0.999999986961484 ...,
0.9999999841675162 1.0000000074505806 0.9999999841675162]
[0.9999999991268851 1.0000000223517418 0.999999986961484 ...,
0.9999999841675162 1.0000000074505806 0.9999999841675162]
...,
[1.0000000198488124 1.0000000074505806 1.000000002568413 ...,
0.9999999888241291 0.9999999925494194 0.0]
[1.000000011001248 0.9999999850988388 0.9999999869323801 ...,
1.0000000186264515 0.9999999925494194 0.0]
[1.000000011001248 0.9999999850988388 0.9999999869323801 ...,
1.0000000186264515 0.9999999925494194 0.0]]
我想用numpy.allclose或numpy.array_equal的,但也使得這裏的感覺。理想情況下,函數應該能夠在測試場景中使用
什麼是_「非常接近」_? – Bart
我認爲你正在尋找像numpy的'assert_almost_equal'這樣的東西。有關示例,請參見[docs](http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.testing.assert_almost_equal.html)。 – jorgeh
爲什麼'allclose'沒有意義? (它廣播!) – user2357112