How to check whether the elements of a given NumPy array is non-zero?
Last Updated :
29 Aug, 2020
In NumPy with the help of any() function, we can check whether any of the elements of a given array in NumPy is non-zero. We will pass an array in the any() function if it returns true then any of the element of the array is non zero if it returns false then all the elements of the array are zero.
Syntax: numpy.any()
Parameter :An array.
Return :It return boolean value(True/False).
Example 1:
Python
import numpy as np
array = np.array([ 4 , 6 , 0 , 0 , 0 , 4 , 89 ])
print (x)
print (np. any (array))
|
Output:
True
Example 2:
Python
import numpy as np
array = np.array([ 0 , 0 , 0 , 0 , 0 , 0 ])
print (x)
print (np. any (array))
|
Output:
False
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...