How to Search a NumPy Array and Find Indexes Where Values Are Odd


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

Source Code

import numpy as np

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

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

Output:

(array([0, 2, 3, 5, 6], dtype=int32),)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments