How to Find Index of Value in NumPy Array


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

Source Code

import numpy as np

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

result1 = np.where(n == 3)
print(result1)

result2 = np.where(n > 2)
print(result2)

Output:

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