- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Python – scipy.linalg.inv
The scipy.linalg package contains a of different functionalities that are used for Linear Algebra. One of them is the inv() function, which is used to find the inverse of a square matrix.
Syntax
scipy.linalg.inv(x)
Where x is a square matrix.
Example 1
Let us consider the following example −
# Import the required libraries from scipy import linalg import numpy as np # defines the array a = np.array([[5, 3], [6, 4]]) print("Input matrix :
", a) # Finding the inverse of a square matrix x = linalg.inv(a) print("
Inverse of Square Matrix A :
", x)
Output
The above program will generate the following output −
Input matrix : [[5 3] [6 4]] Inverse of Square Matrix A : [[ 2. -1.5] [-3. 2.5]]
Example 2
Let us take another example −
# Import the required libraries from scipy import linalg import numpy as np # defines the matrix q = np.array([[[5., 6.], [7., 8.]], [[2, 4], [6, 8]]]) print("Input matrix :
", q) # Finding the inverse of the square matrix m = np.linalg.inv(q) print("
Inverse of the Square Matrix Q :
", m)
Output
The above program will generate the following output −
Input matrix : [[[5. 6.] [7. 8.]] [[2. 4.] [6. 8.]]] Inverse of the Square Matrix Q : [[[-4. 3. ] [ 3.5 -2.5 ]] [[-1. 0.5 ] [ 0.75 -0.25]]]
- Related Articles
- How do I install Python SciPy?
- What are various sub-packages in Python SciPy library?
- How to solve triangular matrix equations using Python SciPy?
- How can discrete Fourier transform be performed in SciPy Python?
- How to solve a circulant matrix equation using Python SciPy?
- Explain how Nelder-Mead algorithm can be implemented using SciPy 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?
- Calculating Euclidean distance using SciPy
- Calculating the Manhattan distance using SciPy
- Calculating the Minkowski distance using SciPy
- Calculating the Hamming distance using SciPy
- What is SciPy in Python? Explain how it can be installed, and its applications?
- How can SciPy be used to calculate the inverse of a matrix in Python?
- How can SciPy be used to calculate the permutations and combination values in Python?
- What is interpolation and how can we implement it in the SciPy Python library?

Advertisements