title: Pearson Correlation between two Matrices
body: <p>So I want to compute the correlation between every row of one matrix and every column of the other matrix. This is with what I have come up, it works, but I think its pretty slow (takes about 60 seconds for two matrices of shape 500x30000 and 500x16).</p>
  
  <pre><code>def matrix_corr(array1,array2):
  
  array1= array1.T #transposed in order to have same dimension in the middle of both matrices
  
  
  corr_pear = np.empty((array1.shape[0],array2.shape[1]))
  
  
  for n in range(array1.shape[0]): #30000 rowvectors
      array1_mean = np.mean(array1[n,:]) #n-th rowvector 
      array1_squared = np.sum(np.square(array1[n,:]-array1_mean))
      for m in range(array2.shape[1]): #256 columnvectors of hypothesis
          array2_mean = np.mean(array1[:,m])
          array2_squared = np.sum(np.square(array1[:,m]-array2_mean))
          corr_pear[n,m] = (np.inner((array1[n,:]-array1_mean),(array2[:,m]-array2_mean))/
          float(math.sqrt(array1_squared*array2_squared)))
  
  return corr_pear
  </code></pre>
  
  <p>I guss there is a more pythonic way to solve this.</p>
  
  <p>I hope someone of you could tell me how to tweak it. </p>
  
  <p>Thanks!</p>