title: Python - Matrix outer product
body: <p>Given two matrices</p>
  
  <pre><code>A: m * r
  B: n * r
  </code></pre>
  
  <p>I want to generate another matrix <code>C: m * n</code>, with each entry <code>C_ij</code> being a matrix calculated by the outer product of <code>A_i</code> and <code>B_j</code>.</p>
  
  <p>For example,</p>
  
  <pre><code>A: [[1, 2],
      [3, 4]]
  
  B: [[3, 1],
      [1, 2]]
  </code></pre>
  
  <p>gives </p>
  
  <pre><code>C: [[[3, 1],  [[1 ,2],
       [6, 2]],  [2 ,4]],
       [9, 3],  [[3, 6],
       [12,4]],  [4, 8]]]
  </code></pre>
  
  <p>I can do it using for loops, like</p>
  
  <pre><code>    for i in range (A.shape(0)):
        for j in range (B.shape(0)):
           C_ij = np.outer(A_i, B_j)
  </code></pre>
  
  <p>I wonder If there is a vectorised way of doing this calculation to speed it up?</p>