Finding eigenvalues and eigenvectors with NumPy
The eigenvalues
are scalar solutions to the equation Ax = ax
, where A
is a two-dimensional matrix and x
is a one-dimensional vector. The eigenvectors
are vectors corresponding to eigenvalues
.
Note
The eigenvalues
and eigenvectors
are fundamental in mathematics, and are used in many important algorithms, such as principal component analysis (PCA). PCA can be used to simplify the analysis of large datasets.
The eigvals()
subroutine in the numpy.linalg
package computes eigenvalues
. The eig()
function gives back a tuple holding eigenvalues
and eigenvectors
.
We will obtain the eigenvalues
and eigenvectors
of a matrix with the eigvals()
and eig()
functions of the numpy.linalg
subpackage. We will check the outcome by applying the dot()
function:
import numpy as np A = np.mat("3 -2;1 0") print("A\n", A) print("Eigenvalues", np.linalg.eigvals(A)) eigenvalues, eigenvectors = np.linalg.eig(A) print("First...