Replace the for loop using the assert functions in numpy.testing