albert - 6 months ago 22

Python Question

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

`numpy`

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

`numpy`

Answer

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()
```