w3resource logo
Python Exercises

Python NumPy: Test if all elements in an array evaluate to True

Python NumPy: Array Object Exercise-23 with Solution

Write a Python program to test if all elements in an array evaluate to True.
Note: 0 evaluates to False in python.

Sample Solution:-

Python Code:

import numpy as np
print(np.all([[True,False],[True,True]]))
print(np.all([[True,True],[True,True]]))
print(np.all([10, 20, 0, -50]))
print(np.all([10, 20, -50]))

Sample Output:

False                                                                  
True                                                                   
False                                                                  
True

Python Code Editor:

import numpy as np
print(np.all([[True,False],[True,True]]))
print(np.all([[True,True],[True,True]]))
print(np.all([10, 20, 0, -50]))
print(np.all([10, 20, -50]))

Improve this sample solution and post your code through Disqus