What is the FASTEST (not simplest) way to compare arrays?
Mostly i will have totally different arrays, that can be marked as unequal after checking the first element.
(a == b).all() # first method
numpy.array_equal(a, b) # second method
This two methods have similar time of execution, so something's not OK. What is the method which terminates just after encountering first mismatch?
This is NOT duplicate of this question: Comparing two numpy arrays for equality, element-wise
all(map(np.equal, a.flat, b.flat)).eqinstead of the numpy one. I was just too lazy to import itfrom operator import eq. And be sure to use the nativeall, too, not thenumpyone. I quickly tested and for me it is faster for arrays of size100or so. Of course, if the arrays happen to be equal you may have a point ...