title: Multiply a 3D matrix with a 2D matrix, return a matrix with the same dimensions as the 2D one
body: <p>In Numpy, say I have a matrix A of dimensions i x j x k, and a matrix B of dimensions k x i. How do I get back a product with dimensions k x i without using a loop?<br />
  For example:</p>
  <pre><code> Let         A = [[[1 2],
                     [3 4]],
                    [[5 6],
                     [7 8]]]
  
               B = [[a b],
                    [c d]]
  </code></pre>
  <p>I would like to get:</p>
  <pre><code>             C = [[a+2c  5b+6d],
                    [3a+4c 7b+8d]]
  </code></pre>
  <p>My current solution is</p>
  <pre><code>np.diagonal(np.dot(A, B), axis1=0, axis2=2)
  </code></pre>
  <p>However, the problem is I'm working with a large data set (<code>A</code> and <code>B</code> have huge dimensions) so <code>np.dot(A, B)</code> would lead to <code>MemoryError</code>. Therefore I want to figure out a better way to solve this without computing the dot product.</p>
  <p>I have looked into functions like <code>einsum</code> and <code>tensordot</code> but I didn't find what I need (or maybe I missed something). I would appreciate if someone could help me out. Thank you!</p>