title: How to do a "generalized" matrix operation in Theano?
body: <p>Let's assume that I have a 4-dimensional tensor <code>A</code> and I would like to multiply it with a 3-dimensional tensor <code>B</code> in the following way:</p>
  
  <pre><code>C[i,k,a,b] = sum_{j,l} A[i,j,k,l]*B[a,j,b,l]
  </code></pre>
  
  <p>This is a generalization of matrix multiplication:</p>
  
  <pre><code>z[i,k] = sum_j x[i,j]*y[j,k]
  </code></pre>
  
  <p>In other words, I pair some indexes of the first tensor with some indexes of the second tensor and then sum over them.</p>