Related Articles
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 ` ` `  ` `  `# Original array ` `array ``=` `np.array([``4``,``6``,``0``,``0``,``0``,``4``,``89``]) ` `print``(x) ` ` `  `# Test whether any of the elements ` `# of a given array is non-zero ` `print``(np.``any``(array)) `

Output:

```True
```

Example 2:

## Python

 `import` `numpy as np ` ` `  `# Original array ` `array ``=` `np.array([``0``,``0``,``0``,``0``,``0``,``0``]) ` `print``(x) ` ` `  `# Test whether any of the elements ` `# of a given array is non-zero ` `print``(np.``any``(array))`

Output:

```False
```

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :