Difference between normed plt.xcorr at 0-lag and np.corrcoef
<p>I am working on a cross correlation between two relatively small time series, but in trying to accomplish I am running into a problem I cannot reconcile myself. To begin, I understand the dependence between <code>plt.xcorr</code> and <code>np.correlate</code>. However, I am having trouble reconciling the difference between <code>plt.xcorr</code> at zero lag and <code>np.corrcoef</code>?</p>

<pre><code>a = np.array([  7.35846410e+08,   8.96271634e+08,   6.16249222e+08,
     8.00739868e+08,   1.06116376e+09,   9.05690167e+08,
     6.31383600e+08])
b = np.array([  1.95621617e+09,   2.06263134e+09,   2.27717015e+09,
     2.27281916e+09,   2.71090116e+09,   2.84676385e+09,
     3.19578883e+09])

np.corrcoef(a,b)
# returns:
array([[ 1.        ,  0.02099573],
      [ 0.02099573,  1.        ]])

plt.xcorr(a,b,normed=True, maxlags=1)
# returns:
array([-1,  0,  1]),
 array([ 0.90510941,  0.97024415,  0.79874158])
</code></pre>

<p>I expected these to return the same result. I clearly do not understand how <code>plt.xcorr</code> is normed, could someone please set me straight?</p>

<p>I used <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xcorr" rel="nofollow">http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xcorr</a></p>

<blockquote>
  <p>normed : boolean, optional, default: True</p>
  
  <p>if True, normalize the data by the autocorrelation at the 0-th lag.</p>
</blockquote>

<p>In the following code, <code>plt_corr</code> equals <code>np_corr</code>.</p>

<pre><code>plt_corr = plt.xcorr(a, b, normed=True, maxlags=6)

c = np.correlate(a, a)  # autocorrelation of a
d = np.correlate(b, b)  # autocorrelation of b
np_corr = np.correlate(a/np.sqrt(c), b/np.sqrt(d), 'full')
</code></pre>

python numpy correlation cross-correlation