Calculating the Inverse of a Matrix
The scipy.linalg.inv is used to find the inverse of a matrix.
Syntax: scipy.linalg.inv(a , overwrite_a , check_finite)
Parameters:
- a: It is a square matrix.
- overwrite_a (Optional): Discard data in the square matrix.
- check_finite (Optional): It checks whether the input matrix contains only finite numbers.
Returns:
- scipy.linalg.inv returns the inverse of the square matrix.
Consider an example where an input x is taken by the function scipy.linalg.inv. This input is the square matrix. It returns y, which is the inverse of the matrix x. Let the matrix be –
Python
# Import the required libraries from scipy import linalg import numpy as np # Initializing the matrix x = np.array([[ 7 , 2 ], [ 4 , 5 ]]) # Finding the inverse of # matrix x y = linalg.inv(x) print (y) |
Output:
[[ 0.18518519 -0.07407407] [-0.14814815 0.25925926]]
SciPy Linear Algebra – SciPy Linalg
The SciPy package includes the features of the NumPy package in Python. It uses NumPy arrays as the fundamental data structure. It has all the features included in the linear algebra of the NumPy module and some extended functionality. It consists of a linalg submodule, and there is an overlap in the functionality provided by the SciPy and NumPy submodules.
Let’s discuss some methods provided by the module and its functionality with some examples.