How to use ndenumerate() function to find the Index of value In Python
It is usually used to find the first occurrence of the element in the given numpy array.
Python3
import numpy as np def ind(array, item): for idx, val in np.ndenumerate(array): if val = = item: return idx # If no item was found return None, other return types might be a problem due to # numbas type inference. a = np.array([ 11 , 12 , 13 , 14 , 15 , 16 , 17 , 15 , 11 , 12 , 14 , 15 , 16 , 17 , 18 , 19 , 20 ]) print (ind(a, 11 )) |
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.