Eigenvectors and Eigenvalues are the tools required to understand linear mapping and transformation. Eigenvalues are solutions to the equation Ax = λx. Here, A is the square matrix, x is the eigenvector, and λ is eigenvalues. The numpy.linalg subpackage provides two functions, eig() and eigvals(). The eig() function returns a tuple of eigenvalues and eigenvectors, and eigvals() returns the eigenvalues.
Eigenvectors and eigenvalues are the core fundamentals of linear algebra. Eigenvectors and eigenvalues are used in SVD, spectral clustering, and PCA.
Let's compute the eigenvectors and eigenvalues of a matrix, as follows:
- Create the matrix using the NumPy mat() function, like this:
# Import numpy
import numpy as np
# Create matrix using NumPy
mat=np.mat([[2,4],[5,7]])
print("Matrix:\n",mat)
This results in the following output:
Matrix: [[2 4]
[5 7]]
- Compute eigenvectors and eigenvalues using the eig() function, like...