title: Vectorize a lookup between two numbers
body: <p>I am trying to find a way to vectorize the following for loop using numpy. This for loop is making my code really drag. The problem that I am having is that I need to look up a value sitting in the dictionary, d, based on the index where the value,val, falls in a range within the array, row.</p>
  
  <pre><code>for i in range(len(row)-1):
      if row[i]&lt;val&lt;=row[i+1]:
          return d[i]*row[-1]
  </code></pre>
  
  <p>I would imagine that I could use np.where and np.logical_and to get between two numbers in the array, but then I need the index to grab the value from a dictionary, and that is the part that I just can't seem to figure out without the loop.</p>