Comparing two NumPy arrays for equality, element-wise
问题 What is the simplest way to compare two NumPy arrays for equality (where equality is defined as: A = B iff for all indices i: A[i] == B[i] )? Simply using == gives me a boolean array: >>> numpy.array([1,1,1]) == numpy.array([1,1,1]) array([ True, True, True], dtype=bool) Do I have to and the elements of this array to determine if the arrays are equal, or is there a simpler way to compare? 回答1: (A==B).all() test if all values of array (A==B) are True. Note: maybe you also want to test A and B