Created
August 5, 2020 08:34
-
-
Save reox/235f84dfed96b1648e012ca0bd1e1c6d to your computer and use it in GitHub Desktop.
Eigenvalues and -vectors of matrix and getting matrix back in numpy
This file contains hidden or 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 | |
A = np.array([[2,1,2.5], [1,3,1], [2.5,1,4]]) | |
# Eigenvalues and -vectors have the property such that: Ax = lx | |
# x ... Eigenvectors | |
# l ... Eigenvalues | |
l, x = np.linalg.eig(A) | |
# it follows: | |
# A = x l x^-1 | |
A_reconstructed = np.matmul(np.matmul(x, l * np.eye(3)), np.linalg.inv(x)) | |
# or in python3, @ is used for matrix multiplication: | |
A_reconstructed = x @ (l * np.eye(3)) @ np.linalg.inv(x) | |
print(A_reconstructed) | |
# array([[2. , 1. , 2.5], | |
# [1. , 3. , 1. ], | |
# [2.5, 1. , 4. ]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment