title: Correlation coefficient between a 2D and a 3D array - NumPy/Python
body: <p>Let</p>
  
  <pre><code>import numpy as np
  A = np.ones([n,m])
  B = np.ones([o,n,m])
  </code></pre>
  
  <p>Is there any way to compute correlation coefficient witout looping such that</p>
  
  <pre><code>C = corr(A,B) = array([1,o])
  </code></pre>
  
  <p>Where <code>m</code>, <code>n</code> and <code>o</code> are used to express dimension.</p>
  
  <p>Loopy Example:</p>
  
  <pre><code>from scipy.stats.stats import pearsonr
  
  A = np.random.random([5,5])
  B = np.random.random([3,5,5])
  C = []
  for i in B:
      C.append(pearsonr(A.flatten(), i.flatten())[0])
  
  C = np.array(C)
  </code></pre>