albert albert - 10 days ago 4
Python Question

Numpy: how I can determine if all elements of numpy array are equal to a number

I need to know if all the elements of an array of

are equal to a number

It would be like:

numbers = np.zeros(5) # array[0,0,0,0,0]
print numbers.allEqual(0) # return True because all elements are 0

I can make an algorithm but, there is some method implemented in


You can break that down into np.all(), which takes a boolean array and checks it's all True, and an equality comparison:

np.all(numbers == 0)
# or equivalently
(numbers == 0).all()