我是python的新手。我试图将图像读入数组并执行SVD(步骤1)。然后将SVD与原始数组相乘(步骤2)。在下面以粗体突出显示的步骤2中,我得到一个错误“形状(10,1024)和(640,1024)未对齐:1024(暗淡1)!= 640(暗淡0)。非常感谢任何帮助。
# Import sample.png into array img as command parameter
img = scipy.misc.imread(inputfile)
print(img.shape)
# Perform SVD on im and obtain individual matrices
P, D, Q = numpy.linalg.svd(img, full_matrices=False)
# Compute overall SVD matrix based on individiual matrices
svd_decomp = numpy.dot(numpy.dot(P, numpy.diag(D)), Q)
# Keep Top entries in svd_decomp
initial = svd_decomp.argsort()
temp = numpy.array(initial)
svd_final = numpy.argpartition(temp,-rank)[-rank:]
print (svd_final.shape)
# Multiply to obtain the best rank-k approximation of the original array
#numpy.dot(svd_decomp * img)
#print (svd_final.dot(img))
print(numpy.dot(svd_final,img))**