Nope Nope - 1 year ago 92
Python Question

Is there a Numpy function to return the first index of something in an array?

I know there is a method for python list to return the first index of something

l = list(1,2,3)
>>> 1

Is there something like that for numpy arrays?

Answer Source

Yes, here is the answer given a Numpy array, array, and a value, item, to search for.

itemindex = numpy.where(array==item)

The result is a tuple with first all the row indices, then all the column indices.

For example if array is two dimensions and it contained your item at two locations then


would be equal to your item and so would



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download