title: Fastest way to find norm of difference of vectors in Python
body: <p>I have a <strong>list of pairs</strong> (say '<strong>A</strong>'), and <strong>two arrays</strong>, '<strong>B</strong>' and '<strong>C</strong>' ( each array has three columns ). The arrays 'B' and 'C 'are collections of coordinates / vectors (3 dimensions). 'A' is a list of pairs of indices; the <strong>first entry in each pair denotes the index of a row in B</strong> and the <strong>second entry in each pair points to the index of a row in C</strong>. As an example:</p>
  
  <pre><code>A = [(0, 0), (0, 1), (0, 3), (1, 2), (2, 2)]
  B = [[ 0.1  0.4  0.5]
      [ 0.7  0.0  0.4]
      [ 0.8  0.4  0.7]
      [ 0.9  0.3  0.8]]
  C = [[ 0.9  0.8  0.9]
      [ 0.3  0.9  0.5]
      [ 0.3  0.4  0.8]
      [ 0.5  0.4  0.3]]
  </code></pre>
  
  <p>For each pair in the list A, I wish to find the <strong>euclidean norm of the difference of vectors</strong> in B and C. That is to say, for the pair (i,j), I wish to find Norm( B[i,:]-C[j,:] ). I wish to do this for all pairs in the fastest way possible.</p>
  
  <p>Presently, I am doing it in the following manner:</p>
  
  <pre><code>import numpy as np
  map( lambda x: np.sqrt( (B[x[0]] - C[x[1]]).dot(B[x[0]] - C[x[1]]) ), A)
  </code></pre>
  
  <p>I find the above technique to be somewhat faster than:</p>
  
  <pre><code>map( lambda x: np.linalg.norm((B[x[0]] - C[x[1]])), A) 
  </code></pre>
  
  <p>I am dealing with <strong>arrays B and C</strong> which have <strong>millions of rows</strong>. Could anyone tell me how I can obtain the above functionality in the <strong>fastest way possible</strong> in <strong>python</strong>?</p>