title: Adapting matrix array multiplication to use Numpy Tensordot
body: <p>I'm trying to speed up my code to perform some numerical calculations where I need to multiply 3 matrices with an array. The structure of the problem is the following:</p>
  
  <ul>
  <li>The array as a shape of (N, 10)</li>
  <li>The first matrix is constant along the dynamic dimension of the array and has a shape of (10, 10)</li>
  <li>The other two matrices vary along the first dimension of the array and have a (N, 10, 10) shape</li>
  <li>The result of the calculation should be an array with (N, shape)</li>
  </ul>
  
  <p>I've implemented a solution using for loops that is working, but I'd like to have a better performance so I'm trying to use the numpy functions. I've tried using numpy.tensordot but when multiplying the dynamic matrices with the array I get a shape of (N, 10, N) instead of (N, 10)</p>
  
  <p>My for loop is the following:</p>
  
  <pre><code>res = np.zeros(temp_rho.shape, dtype=np.complex128)
  for i in range(temp_rho.shape[0]):
      res[i] = np.dot(self.constMatrix, temp_rho[i])  
      res[i] += np.dot(self.dinMat1[i], temp_rho[i])
      res[i] += np.dot(self.dinMat2[i], np.conj(temp_rho[i]))
  #temp_rho.shape = (N, 10)
  #res.shape = (N, 10)
  #self.constMatrix.shape = (10, 10)
  #self.dinMat1.shape = (N, 10, 10)
  #self.dinMat2.shape = (N, 10, 10)
  </code></pre>
  
  <p>How should this code be implemented dot products of numpy, returning the correct dimensions?</p>