title: Procrustes Analysis with NumPy?
body: <p>Is there something like Matlab's <a href="http://www.mathworks.com/help/stats/procrustes.html"><code>procrustes</code></a> function in NumPy/SciPy or related libraries? </p>
  
  <hr>
  
  <p>For reference. Procrustes analysis aims to align 2 sets of points (in other words, 2 shapes) to minimize square distance between them by removing scale, translation and rotation warp components. </p>
  
  <p>Example in Matlab:</p>
  
  <pre><code>X = [0 1; 2 3; 4 5; 6 7; 8 9];   % first shape
  R = [1 2; 2 1];                  % rotation matrix
  t = [3 5];                       % translation vector
  Y = X * R + repmat(t, 5, 1);     % warped shape, no scale and no distortion
  [d Z] = procrustes(X, Y);        % Z is Y aligned back to X
  Z
  
  Z =
  
    0.0000    1.0000
    2.0000    3.0000
    4.0000    5.0000
    6.0000    7.0000
    8.0000    9.0000
  </code></pre>
  
  <p>Same task in NumPy: </p>
  
  <pre><code>X = arange(10).reshape((5, 2))
  R = array([[1, 2], [2, 1]])
  t = array([3, 5])
  Y = dot(X, R) + t
  Z = ???
  </code></pre>
  
  <p>Note: I'm only interested in aligned shape, since square error (variable <code>d</code> in Matlab code) is easily computed from 2 shapes. </p>