title: Computing autocorrelation of vectors with numpy
body: <p>I'm struggling to come up with a non-obfuscating, efficient way of using numpy to compute a self correlation function in a set of 3D vectors.</p>
  
  <p>I have a  set of vectors in a 3d space, saved in an array</p>
  
  <pre><code>a = array([[ 0.24463039,  0.58350592,  0.77438803],
         [ 0.30475903,  0.73007075,  0.61165238],
         [ 0.17605543,  0.70955876,  0.68229821],
         [ 0.32425896,  0.57572195,  0.7506    ],
         [ 0.24341381,  0.50183697,  0.83000565],
         [ 0.38364726,  0.62338687,  0.68132488]])
  </code></pre>
  
  <p>their self correlation function is defined as 
  <a href="https://i.stack.imgur.com/z70yG.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z70yG.gif" alt="enter image description here"></a></p>
  
  <p>in case the image above doesn't stay available, the formula is also printed below:
  C(t,{v}<em>n) = \frac 1{n-t}\sum</em>{i=0}^{n-1-t}\vec v_i\cdot\vec v_{i+t}</p>
  
  <p>I'm struggling to code this up in an efficient way, non-obfuscating way. I can compute this expliticly with two nested for loops, but that's slow. There is a fast way of doing it by using one of the embedded functions in numpy, but they seem to be using an entirely different definition of correlation function. A similar problem has been solved here, <a href="https://stackoverflow.com/questions/643699/how-can-i-use-numpy-correlate-to-do-autocorrelation">How can I use numpy.correlate to do autocorrelation?</a> but that doesn't handle vectors. Do you know how can I solve this?</p>