I have a matrix A which I need to compute the SVD of, set the last singular value to 0 and then recombine(SVD cleanup) in numpy. I did this:
t4 = np.random.randn(3, 3)
u, s, vh = np.linalg.svd(t4, full_matrices=False)
s[-1] = 0
t5 = u @ s @ vh
I am expecting the result to be a 3x3 matrix but the result seems to be a row vector of shape (3,).
Can you all please suggest what I might be doing wrong? Thanks!
The s
is returned as a 1D array with the terms in the diagonal, you can construct a matrix from, using diag
t5 = u @ np.diag(s) @ vh