有机会将值os不匹配存储在一个变量中吗?
np.testing.assert_array_almost_equal(x,y,decimal=2)
如您所见,函数的输出是布尔值和断言错误。不匹配值出现在消息中
AssertionError:
Arrays are not almost equal to 2 decimals
(mismatch 57.095709571%)
x: array([ 0.01, 0.01, 0.01, ..., -0. , 0.01, 0.01])
y: array([0.02, 0.02, 0.02, ..., 0.02, 0.02, 0.02])
你可以做:
try:
np.testing.assert_array_almost_equal(x,y,decimal=2)
except AssertionError as e:
mismatch = e.args[0].split('\n')[3].split(' ')[1][:-2]
那么不匹配项将包含具有您要查找的值的str。在您的示例中:
mismatch = 57.095709571
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句