title: Finding closest values in two numpy arrays
body: <p>The aim here is speed- I am trying to get away from looping through the arrays in question. It can however be assumed that the two arrays are sorted.</p>
  
  <pre><code>a = np.arange(10)
  b = np.array([2.3, 3.5, 5.8, 13])
  c = somefunc(a,b)
  </code></pre>
  
  <p>Now <code>somefunc</code> should find the indices of <code>a</code> for which the values in <code>b</code> are closest too, i.e.</p>
  
  <pre><code>In []: c
  Out[]: array([2, 3or4, 6, 9])  #3 or 4 depending on python2 or 3
  </code></pre>
  
  <p>Once again, this could be done with a loop, but I am looking for something a lot faster. I got quite close by taking the absolute difference type approach, something like:</p>
  
  <pre><code>np.argmin(np.abs(a[:, np.newaxis] - b), axis=0)
  </code></pre>
  
  <p>But even this is a little slow as a lot of unnecessary subtractions are done.</p>