- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Finding inverse of a square matrix using SciPy library
SciPy library has scipy.linalg.inv() function for finding the inverse of a square matrix. Let’s understand how we can use this function to calculate the inverse of a matrix −
Example
Inverse of a 2 by 2 matrix
#Importing the scipy package import scipy.linalg #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.inv() function M = scipy.linalg.inv(A) #Printing the result print('Inverse of
{}
is {}'.format(A,M))
Output
Inverse of [[3. 3.5] [3.2 3.6]] is [[-9. 8.75] [ 8. -7.5 ]]
Example
Inverse of a 3 by 3 matrix
import scipy import numpy as np A = np.array([[2,1,-2],[1,0,0],[0,1,0]]) M = scipy.linalg.inv(A) print('Inverse of
{}
is {}'.format(A,M))
Output
Inverse of [[ 2 1 -2] [ 1 0 0] [ 0 1 0]] is [[ 0. 1. 0. ] [ 0. -0. 1. ] [-0.5 1. 0.5]]
- Related Articles
- Finding determinant of a square matrix using SciPy library
- Finding inverse of a matrix using Gauss Jordan Method in C++
- Finding square root of a number without using library functions - JavaScript
- How to find the Eigenvalues and Eigenvectors of a square matrix using SciPy?
- How can SciPy be used to calculate the inverse of a matrix in Python?
- PyTorch – How to compute the inverse of a square matrix?
- How to implement ‘cubic’ 1-D interpolation using SciPy library?
- Comparing ‘cubic’ and ‘linear’ 1-D interpolation using SciPy library
- How to solve a circulant matrix equation using Python SciPy?
- How to solve triangular matrix equations using Python SciPy?
- Implementing K-means clustering of Diabetes dataset with SciPy library
- Finding square root of a number without using Math.sqrt() in JavaScript
- Compute the multiplicative inverse of a matrix object with matrix() in Python
- What is the use of scipy.interpolate.interp1d class of SciPy python library?
- How to solve Hermitian positive-banded matrix equation using Python SciPy?

Advertisements