title: In python, How do we find the Correlation Coefficient between two matrices?
body: <p>I have got two matrices say, T1 and T2 each of size mxn. I want to find the correlation coefficient between two matrices<br>
  So far I haven't used any built-in library function for it. I am doing the following steps for it:<br>
  First I calculate the mean of the two matrices as:  </p>
  
  <pre><code>M1 = T1.mean()
  M2 = T2.mean()
  </code></pre>
  
  <p>and then I subtract the mean from the corresponding matrices as:  </p>
  
  <pre><code>A = np.subtract(T1, M1)
  B = np.subtract(T2, M2)
  </code></pre>
  
  <p>where np is the numpy library and A and B are the resulting matrices after doing the subtraction.<br>
  Now , I calculate the correlation coefficent as:</p>
  
  <pre><code>alpha = np.sum(A*B) / (np.sqrt((np.sum(A))*np.sum(B)))
  </code></pre>
  
  <p>However, the value i get is far greater than 1 and in not meaningful at all. It should be in between 0 and 1 to get some meaning out of it.<br>
  I have also tried to make use absolute values of matrix A and B, but that also did'nt work.<br>
  I also tried to use :  </p>
  
  <pre><code>np.sum(np.dot(A,B.T)) instead of np.sum(A*B)  
  </code></pre>
  
  <p>in the numerator , but that also didn't work.<br>
  Edit1:<br>
  This is the formula that I intend to calculate:<br>
   <a href="https://i.stack.imgur.com/TSwYZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TSwYZ.png" alt="This image shows the actual formula to be calculated"></a></p>
  
  <p>In this image, C is one of the matrices and T is another one.<br>
  'u' is the mean symbol.  </p>
  
  <p>Can somebody tell me where actually i am doing the mistake.</p>