Compare (assert equality of) two complex data structures containing numpy arrays in unittest

后端 未结 7 1762
醉酒成梦
醉酒成梦 2020-12-06 16:25

I use Python\'s unittest module and want to check if two complex data structures are equal. The objects can be lists of dicts with all sorts of values: numbers,

7条回答
  •  星月不相逢
    2020-12-06 17:02

    check numpy.testing.assert_almost_equal which "raises an AssertionError if two items are not equal up to desired precision", e.g.:

     import numpy.testing as npt
     npt.assert_almost_equal(np.array([1.0,2.3333333333333]),
                             np.array([1.0,2.33333334]), decimal=9)
    

提交回复
热议问题