I'm writing unit tests for my simulation and want to check that for specific parameters the result, a numpy array, is zero. Due to calculation inaccuracies, small values are also accepted (1e-7). What is the best way to assert this array is close to 0 in all places?
np.testing.assert_array_almost_equal(a, np.zeros(a.shape))andassert_allclosefail as the relative tolerance isinf(or 1 if you switch the arguments) Docu- I feel like
np.testing.assert_array_almost_equal_nulp(a, np.zeros(a.shape))is not precise enough as it compares the difference to the spacing, therefore it's always true fornulps >= 1and false otherways but does not say anything about the amplitude ofaDocu - Use of
np.testing.assert_(np.all(np.absolute(a) < 1e-7))based on this question does not give any of the detailed output, I am used to by othernp.testingmethods
Is there another way to test this? Maybe another testing package?
assert_allclosefor this?np.zerosdoes not work, it's probably better to usenp.zeros_like.