﻿ NumPy: Find indices of elements equal to zero in a NumPy array - w3resource # NumPy: Find indices of elements equal to zero in a NumPy array

## NumPy: Array Object Exercise-115 with Solution

Write a NumPy program to find indices of elements equal to zero in a NumPy array.

Sample Solution:

Python Code:

``````import numpy as np
nums = np.array([1,0,2,0,3,0,4,5,6,7,8])
print("Original array:")
print(nums)
print("Indices of elements equal to zero of the said array:")
result = np.where(nums == 0)
print(result)
```
```

Sample Output:

```Original array:
[1 0 2 0 3 0 4 5 6 7 8]
Indices of elements equal to zero of the said array:
[1 3 5]
```

Pictorial Presentation: Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

﻿

## Python: Tips of the Day

Set comprehension:

```>>> m = {x ** 2 for x in range(5)}
>>> m
{0, 1, 4, 9, 16}
```