Skip to content

Instantly share code, notes, and snippets.

Last active July 23, 2019 05:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import numpy as np
from numpy.linalg import svd
# define your matrix as a 2D numpy array
A = np.array([[4, 0], [3, -5]])
U, S, VT = svd(A)
print("Left Singular Vectors:")
print("Singular Values:")
print("Right Singular Vectors:")
# check that this is an exact decomposition
# @ is used for matrix multiplication in Py3, use np.matmul with Py2
print(U @ np.diag(S) @ VT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment