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(U) | |
print("Singular Values:") | |
print(np.diag(S)) | |
print("Right Singular Vectors:") | |
print(VT) | |
# 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