

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find the Eigenvalues and Eigenvectors of a square matrix using SciPy?
We can find the Eigenvalues and Eigenvectors for a square matrix, say A, with the help of following relation −
SciPy library has scipy.linalg.eig() function for computing the eigenvalues and eigenvectors of a square matrix.
Let’s understand how we can use this function to calculate the inverse of a matrix −
Example
Eigenvalues and Eigenvectors of a 2 by 2 matrix
#Importing the scipy package import scipy #Importing the numpy package import numpy as np #Declaring the numpy array(Square Matrix) A = np.array([[3,3.5],[3.2,3.6]]) #Passing the values to scipy.linalg.eig() function eigvalues, eigvectors = scipy.linalg.eig(A) #Printing the result for eigenvalues print(eigvalues) #Printing the result for eigenvectors print(eigvectors)
Output
[-0.06005952+0.j 6.66005952+0.j] [[-0.75283678 -0.6911271 ] [ 0.65820725 -0.72273324]]
Example
Eigenvalues and Eigenvectors of a 3 by 3 matrix
import scipy import numpy as np A = np.array([[2,1,-2],[1,0,0],[0,1,0]]) eigvalues, eigvectors = scipy.linalg.eig(A) print(eigvalues) print(eigvectors)
Output
[-1.+0.j 2.+0.j 1.+0.j] [[-0.57735027 -0.87287156 0.57735027] [ 0.57735027 -0.43643578 0.57735027] [-0.57735027 -0.21821789 0.57735027]]
- Related Questions & Answers
- PyTorch – How to compute the eigenvalues and eigenvectors of a square matrix?
- Finding determinant of a square matrix using SciPy library
- Finding inverse of a square matrix using SciPy library
- How to solve a circulant matrix equation using Python SciPy?
- How to solve banded matrix equations using Python SciPy?
- How to solve triangular matrix equations using Python SciPy?
- How to solve Toeplitz matrix equation using Python SciPy?
- Compute the eigenvalues of a complex Hermitian or real symmetric matrix in Python
- How to multiply single row matrix and a square matrix in R?
- How to create a matrix that computes the Discrete Fourier transform (DFT) of a sequence using SciPy.
- A square matrix as sum of symmetric and skew-symmetric matrix ?
- PyTorch – How to compute the determinant of a square matrix?
- PyTorch – How to compute the inverse of a square matrix?
- Spiraling the elements of a square matrix JavaScript
- How to solve Hermitian positive-banded matrix equation using Python SciPy?
Advertisements