Asked By – cyborg
How can I find the index of the first occurrence of a number in a Numpy array?
Speed is important to me. I am not interested in the following answers because they scan the whole array and don’t stop when they find the first occurrence:
itemindex = numpy.where(array==item) nonzero(array == item)
Note 1: none of the answers from that question seem relevant Is there a Numpy function to return the first index of something in an array?
Note 2: using a C-compiled method is preferred to a Python loop.
Now we will see solution for issue: Numpy: find first index of value fast
There is a feature request for this scheduled for Numpy 2.0.0: https://github.com/numpy/numpy/issues/2269