How to Find Indexes Where Values Are Even From a NumPy Array


In this example we will show how to search a NumPy array and find the indexes where the values are even in Python.

Source Code

import numpy as np

n = np.array([1, 2, 3, 3, 2, 3, 1])

result = np.where(n % 2 == 0)
print(result)

Output:

(array([1, 4], dtype=int32),)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments