Skip to content

Instantly share code, notes, and snippets.

@kumanna
Created April 19, 2024 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumanna/955bc261c86b7dfe10aa97320b5ce0c0 to your computer and use it in GitHub Desktop.
Save kumanna/955bc261c86b7dfe10aa97320b5ce0c0 to your computer and use it in GitHub Desktop.
import numpy as np
e = 0.0
for i in range(1000):
A = np.random.randn(10,10)
U, S, Vh = np.linalg.svd(A)
V = Vh.T
A1 = S[0] * (np.outer(U[:,0], V[:,0]))
e = e + np.linalg.norm(A - A1, 2)**2
print(e / 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment