Calculating the Pseudo Inverse of a Matrix
To evaluate the (Moore-Penrose) pseudo-inverse of a matrix, scipy.linalg.pinv is used.
Syntax: scipy.linalg.pinv(a , cond , rcond , return_rank , check_finite)
Parameters:
- a: It is the Input Matrix.
- cond, rcond (Optional): It is the cutoff factor for small singular values.
- return_rank (Optional): It returns the effective rank of the matrix if the value is True.
- check_finite (Optional): It checks if the input matrix consists of only finite numbers.
Returns:
- scipy.linalg.pinv returns the pseudo-inverse of the input matrix.
Example: The scipy.linalg.pinv takes a matrix x to be pseudo-inverted. It returns the pseudo-inverse of matrix x and the effective rank of the matrix.
Python
# Import the required libraries from scipy import linalg import numpy as np # Initializing the matrix x = np.array([[ 8 , 2 ] , [ 3 , 5 ] , [ 1 , 3 ]]) # finding the pseudo inverse of matrix x y = linalg.pinv(x) print (y) |
Output:
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.