title: How to find the closest corresponding vectors between two coordinate matrices?
body: <p>I have the following problem in Python I need to solve: </p>
  
  <p>Given two coordinate matrices (NumPy ndarrays)  <code>A</code> and <code>B</code>, find for all coordinate vectors <code>a</code> in <code>A</code> the corresponding coordinate vectors <code>b</code> in <code>B</code>, such that the Euclidean distance <code>||a-b||</code> is minimized. The coordinate matrices <code>A</code> and <code>B</code> can have different number of coordinate vectors (that is, different number of rows).</p>
  
  <p>This method should return a matrix of coordinate vectors <code>C</code> where the ith vector <code>c</code> in <code>C</code> is the vector from <code>B</code> that minimizes the Euclidean distance with the ith coordinate vector <code>a</code> in <code>A</code>.</p>
  
  <p>For example, lets say </p>
  
  <p><code>A = np.array([[1,1], [3,4]])</code> and <code>B = np.array([[1,2], [3,6], [8,1]])</code></p>
  
  <p>The Euclidean distances between the vector <code>[1,1]</code> in <code>A</code> and the vectors in <code>B</code> are: </p>
  
  <pre><code>1, 5.385165, 7
  </code></pre>
  
  <p>So the first vector in <code>C</code> would be <code>[1,2]</code></p>
  
  <p>Similarly the distances for the vector <code>[3,4]</code> in <code>A</code> and the vectors in <code>B</code> are:</p>
  
  <pre><code>2.828427, 2, 5.830952  
  </code></pre>
  
  <p>So the second and last vector in <code>C</code> would be <code>[3,6]</code></p>
  
  <p>So <code>C = [[1,2], [3,6]]</code> </p>
  
  <p>How to code this efficiently in Python?</p>