-1

SVD is equal to UΣVT, where U - m * k matrix,Σ - k * k diagonal matrix, VT - transposed k * m matrix. Also UΣVT can be determined as A = u1σ1vT1 + u2σ2vT2 + u3σ3vT3 where u1 - first column of U, σ1 - first element of Σ, vT1 - first column of V. Scipy contains function svd(a), which returns UΣVT. How to find for example a = u2σ2vT2 + u3σ3vT3 without cycles.

Derkinfel
  • 1
  • 1
  • please provide an example of input and the expected output – mozway Dec 19 '21 at 11:11
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 25 '21 at 22:40

1 Answers1

0

The reconstruction can be performed by matrix multiplication

U, s, VT = la.svd(A)
np.allclose((U * s) @ VT, A)
np.allclose(U @ np.diag(s) @ VT, A)

If you find the second singular value as s[1] and the thrid as s[2], if you give an arbitrary set of indices, you can reconstruct the sum as

(U[:,indices] * s[indices]) @ VT[indices,:]

Take for example the matrix

A = np.diag(np.arange(5))
array([[0., 0., 0., 0., 0.],
       [0., 1., 0., 0., 0.],
       [0., 0., 2., 0., 0.],
       [0., 0., 0., 3., 0.],
       [0., 0., 0., 0., 4.]])

The sum you mentioned is calculated as

(U[:,2-1:3] * s[2-1:3]) @ VT[2-1:3,:]
array([[0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0.],
       [0., 0., 2., 0., 0.],
       [0., 0., 0., 3., 0.],
       [0., 0., 0., 0., 0.]])
Bob
  • 13,867
  • 1
  • 5
  • 27