title: Multiple dimension matrix multiplication in Python
body: <p>I have a matrix <code>M</code>, <code>M.shape</code> = <code>(4, 4)</code> and <code>M[1,1].shape</code>=<code>(600,300)</code>.
  Each <code>M[i,j]</code> is calculated by passing a <code>meshgrid</code>. For Example</p>
  
  <pre><code>x=300
  t=np.linspace(0, np.pi, num=x)
  p=np.linspace(0,2*np.pi,num=2*x)
  [T,P]=np.meshgrid(t,p)
  M[1,1]=np.sin(T)*np.cos(P)
  </code></pre>
  
  <p>Each element of M is a different combination of <code>sin</code> and <code>cos</code>.</p>
  
  <p>Next I have <code>x</code>, such that <code>x.shape</code>=<code>(4, 600, 300)</code>. x is calculated as follows:</p>
  
  <pre><code>for j in xrange(n):
      x[0]+=np.sin(T)*np.sin(time[j])
      x[1]+=np.sin(T)*np.sin(time[j])
      x[2]+=np.sin(P)*np.cos(time[j])
      x[3]+=np.sin(P)*np.cos(time[j])
  </code></pre>
  
  <p>where <code>time[j]</code> is some number. </p>
  
  <p>I want to know how to compute transpose(x).M.X. So this should come to be a quantity of shape(600,300). I have computed <code>a = np.tensordot(M,x,axes=[1,0])</code> which yields <code>a.shape</code>=<code>(4,600,300)</code>.</p>
  
  <p>Firstly, is this correct? Secondly. I how to take the transpose and compute transpose(x).M.x?</p>