Best way to assert for numpy.array equality?

后端 未结 6 1135
长情又很酷
长情又很酷 2020-12-13 16:37

I want to make some unit-tests for my app, and I need to compare two arrays. Since array.__eq__ returns a new array (so TestCase.assertEqual fails)

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 17:18

    Since Python 3.2 you can use assertSequenceEqual(array1.tolist(), array2.tolist()).

    This has the added value of showing you the exact items in which the arrays differ.

提交回复
热议问题