How to use enumerate() function to find the Index of value In Python

Here we are using the enumerate function and then checking the value with the target value.

Python3




import numpy as np
a = np.array([11, 12, 13, 14, 15, 16, 17, 15,
              11, 12, 14, 15, 16, 17, 18, 19, 20])
print(next(i for i, x in
           enumerate(a) if x == 17))


Output:

6


How to find the Index of value in Numpy Array ?

In this article, we are going to find the index of the elements present in a Numpy array.

Similar Reads

Using where() Method

where() method is used to specify the index of a particular element specified in the condition....

Get the index of elements in the Python loop

...

Using ndenumerate() function to find the Index of value

...

Using enumerate() function to find the Index of value

...

Contact Us