vectorizing sliding window 2d correlation <p>I have two matrices, call them matrix A and matrix B.</p> <ul> <li>A is n_1*n_2</li> <li>B is m_1*m_2</li> </ul> <p>for the sake of simplicity I will assume <code>n_1&lt;m_1</code>, <code>n_2&lt;m_2</code>.</p> <p>I would like to calculate the sliding window correlation between the two, i.e. I convert A to be <code>n_1*n_2</code> vector, and I run 2 loops over B on for rows the other for columns, iteration I pick the first <code>n_1,n_2</code> rows and columns of B, convert them to a vector and then calculate the correlation between them.</p> <p>Is there a way of vectorizing it to reduce the loops?</p>