title: Numpy equivalent of list.index
body: <p>In a low-level function that is called many times, I need to do the equivalent of python's list.index, but with a numpy array.  The function needs to return when it finds the first value, and raise ValueError otherwise.  Something like:</p>
  
  <pre><code>&gt;&gt;&gt; a = np.array([1, 2, 3])
  &gt;&gt;&gt; np_index(a, 1)
  0
  &gt;&gt;&gt; np_index(a, 10)
  Traceback (most recent call last):    
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  ValueError: 10 not in array
  </code></pre>
  
  <p>I want to avoid a Python loop if possible.  <code>np.where</code> isn't an option as it always iterates through the entire array; I need something that stops once the first index is found.</p>
  
  <hr>
  
  <p><strong>EDIT</strong>: Some more specific information related to the problem.</p>
  
  <ul>
  <li><p>About 90% of the time, the index I'm searching for is in the first 1/4 to 1/2 of the array.  So there's potentially a factor of 2-4 speedup at stake here.  The other 10% of the time the value is not in the array at all.</p></li>
  <li><p>I've profiled things already, and the call to <code>np.where</code> is the bottleneck, taking up at least 50% of the total runtime.</p></li>
  <li><p>It is not essential that it raise a <code>ValueError</code>; it just has to return something that obviously indicates that the value isn't in the array.</p></li>
  </ul>
  
  <p>I will probably code up a solution in Cython, as suggested.</p>