编码最佳等级k近似

时间:2014-04-15 05:35:17

标签: python arrays math numpy

此代码尝试计算最佳k-rank近似值。但我一直收到这个错误:

Traceback (most recent call last):
  File "frau.py", line 50, in <module>
    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)

这是我的代码

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 <= k:
        column = vTran[:,j - 1]
        colie = U[:,j - 1]
        a = a + (column * s[:,j - 1] * colie)
        j = j + 1
    return a

我的头脑是一个筛子。我只是不知道该怎么做。我需要在这里解决什么?

0 个答案:

没有答案