Last active
July 23, 2019 05:16
-
-
Save KhyatiMahendru/7bb8c7f9ffdc37a664d5e64789b36f45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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