I know there is a method for a Python list to return the first index of something:
>>> l = [1, 2, 3] >>> l.index(2) 1
Is there something like that for NumPy arrays?
Yes, given an array,
array, and a value,
item to search for, you can use
itemindex = numpy.where(array==item)
The result is a tuple with first all the row indices, then all the column indices.
For example, if an array is two dimensions and it contained your item at two locations then
would be equal to your item and so would be: