title: Numpy solution to avoid nested loops for tensor construction
body: <p>I need to perform the following tensor operation:</p>
  
  <pre><code>T[i,j,k] = A[i,k]*B[j,k]
  
  </code></pre>
  
  <p>My brute force solution is:</p>
  
  <pre><code>T = np.zeros(shape=(N,N,N))
  for i in range(N):
     for j in range(N):
        for k in range(N):
           T[i,j,k] = A[i,k] * B[j,k]
  </code></pre>
  
  <p>Is there a more optimal numpy approach to this? (Note: this is not a simple outer product.) I imagine it involves using np.tensordot with an appropriate axes value, but the documentation does not make it very clear how to use it.</p>
  
  <p>This will also in the end need to work in general for any number of k dimensions:</p>
  
  <pre><code>T[i,j,k1,k2,k3,...] = A[i,k1,k2,k3,...]*B[j,k1,k2,k3,...]
  </code></pre>