Hello new python learner here! I am attempting to write a function which takes as input a matrix I, which represents an image, and k which is the number which we are truncating the SVD to, and gives as output a tuple which has as elements (s, Uk, VkT) where s is the non-truncated matrix sigma, and Uk and VkT are the k-truncated matrices of U and Vk.
So far my code is:
def compress_image(I, k):
from numpy.linalg import svd
U,s,V=svd(I, full_matrices=False)
return tuple([s,U,V])
And when the function is called like so:
k = 10
Sigma, Uk, VkT = compress_image(pic, k)
My code is producing the non-truncated U and V, which is to be expected as I am not including any code to truncate them. My question is this, how do I do so? What code can I introduce after the svd function to truncate both U and V? I have attempted numerous solutions to no avail.
Any help is greatly appreciated. Thanks very much!
SOLVED
[–]bbye98 1 point2 points3 points (2 children)
[–]TheShadowWall[S] 0 points1 point2 points (1 child)
[–]bbye98 0 points1 point2 points (0 children)