kursdragon
kursdragon

Reputation: 77

Creating a lower rank matrix approximation using numpy in python 3

I'm trying to understand how to create a lower rank matrix approximation using numpy. I've created a 2-D array in numpy as well as the SVD for this matrix. But what I'm wondering now is how would I go about creating an approximation for instance of rank 2 of this matrix. If I'm understanding correctly all that would entail is changing the Sigma array of the SVD to only contain the 2 largest numbers? And since it is already ordered this would entail just zeroing out all of the other columns besides the first 2?

For instance if my arrays were as such

#This is my 2-D array which holds my original values
listA
#This is the SVD of this list
listSVD = np.linalg.svd(listA)
u, s, v = listSVD

Would it now just basically be that our rank 2 approximation of this would involve zeroing out all of the columns past the second column in the s and that would be our approximation?

Upvotes: 3

Views: 3269

Answers (1)

kursdragon
kursdragon

Reputation: 77

Nvm I figured it out, so basically yea you just need to zero out the values that are left in the s matrix!

Upvotes: 2

Related Questions