title: Coding Best rank k approximation
body: <p>This code tries to compute the best k-rank approximation. But I keep getting this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "frau.py", line 50, in &lt;module&gt;
      secondRank = matrixExponentiation(2,theMatrix)
    File "frau.py", line 34, in matrixExponentiation
      a = a + (column * s[:,j - 1] * colie)
  ValueError: operands could not be broadcast together with shapes (4,315) (315,175)
  </code></pre>
  
  <p>Here is my code</p>
  
  <pre><code>def matrixExponentiation(k, A):
      j = 1
      a = numpy.zeros(shape = A.shape)
      U, s, V = numpy.linalg.svd(A, compute_uv = True)
      print U.shape, s.shape, V.shape
      vTran = V.T
      while j &lt;= k:
          column = vTran[:,j - 1]
          colie = U[:,j - 1]
          a = a + (column * s[:,j - 1] * colie)
          j = j + 1
      return a
  </code></pre>
  
  <p>My mind is a sieve. I just do not know what to do. What do I need to fix here?</p>