Overview
- When a square matrix is multiplied with its inverse matrix, the resulatant matrix is the identity matrix.
- The function inv() of the numpy.linalg module returns the inverse matrix of a given matrix.
- Not all matrices have their inverse matrices. The matrices that do not have an inverse are called singular matrices.
Example
# Example Python program that finds the inverse matrix of a given matrix
import numpy
# Format of floating point numbers while printing
numpy.set_printoptions(suppress=True, formatter={'float_kind':'{:0.2f}'.format})
# Create a square matrix
numbers = numpy.arange(1, 8, 2)
matrix = numbers.reshape(2, 2)
print("Matrix:")
print(matrix)
# Find the inverse of the matrix
inverse = numpy.linalg.inv(matrix)
print("Inverse of the matrix:")
print(inverse)Output
Matrix:
[[1 3]
[5 7]]
Inverse of the matrix:
[[-0.88 0.38]
[0.62 -0.12]]