w3resource logo
Python Exercises

Python NumPy: Test whether any array element along a given axis evaluates to True

Python NumPy: Array Object Exercise-24 with Solution

Write a Python program to test whether any array element along a given axis evaluates to True.
Note: 0 evaluates to False in python.

Sample Solution:-

Python Code:

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

Sample Output:

False                                                                  
True                                                                   
True                                                                   
True

Python Code Editor:

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

Improve this sample solution and post your code through Disqus