2015-12-02 60 views
0

我正在处理像(110,80,817)这样的大型3D数组,并且希望在某些单元测试中比较两个数组。但是,numpy.assert_almost_equal的默认输出不能帮助我很容易地找出错误。例如:查找失败的索引numpy.assert_almost_equal

>     raise AssertionError(msg) 
E     AssertionError: 
E     Arrays are not almost equal to 7 decimals 
E 
E     (mismatch 0.0314621119395%) 
E     x: array([[[ 0., 0., 0., ..., 0., 0., 0.], 
E       [ 0., 0., 0., ..., 0., 0., 0.], 
E       [ 0., 0., 0., ..., 0., 0., 0.],... 
E     y: array([[[ 0., 0., 0., ..., 0., 0., 0.], 
E       [ 0., 0., 0., ..., 0., 0., 0.], 
E       [ 0., 0., 0., ..., 0., 0., 0.],... 

有没有方法可以轻松查看哪些3D索引失败此断言?

回答

1

您可以使用np.isclosenp.where结合本

idx = zip(*np.where(~np.isclose(a, b, atol=0, rtol=1e-7))) 

现在idx将所有的指标(x,y,z)这里断言失败的列表。

+0

太棒了!谢谢您的帮助。 –