title: Numpy rewriting operation using einsum
body: <p>I am trying to implement PCA in python.
  Currently I am using this code to represent the data back into the initial dimensions from the low dimensional data and the principal components:</p>
  
  <pre><code>sameDimRepresentation = lowDimRepresentation[:, np.newaxis] * principalComponents.T
  sameDimRepresentation = sameDimRepresentation.sum(axis=2)
  </code></pre>
  
  <p>What the code does:</p>
  
  <p>for each row in <code>lowDimRepresentation</code> it computes the product between each element of the row (seen as a scalar) and each of the row vectors of principal components (column vectors of <code>principalComponents.T</code>) and then it sums all these product vectors up (line 2)</p>
  
  <pre><code>lowDimRepresentation: an array of x by 100 
  principalComponents: an array of 100 by 784
  
  resulting array: x by 784
  </code></pre>
  
  <p>This method works fine when using x = 10000 but after that I get a memory error.</p>
  
  <p>I know <code>einsum</code> is more memory efficient, I was trying to rewrite the same code with it but I did not manage.</p>
  
  <p>Can someone help me with that?</p>
  
  <p>Worst case I just split the 60000 cases into batches of 10000 and I run those bits, but I was hoping to achieve something more elegant.</p>
  
  <p>Thanks a lot!</p>