Articles

Program to find inverse of a matrix in Python

Program to find inverse of a matrix in Python


In this python programming article, we are going to learn

  • program to find inverse of a matrix in python

Program to find inverse of a matrix in Python

The program to find inverse of a matrix in python is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

import numpy as np

mat1 = [[11,32,13],
        [43,58,62],
        [75,81,92]]

matrix = np.array(mat1)

print("The inverse is:\n", np.linalg.inv(matrix))

The output of the inverse of a matrix in python program is as follows:

 

The inverse is:
 [[ 0.02181919 -0.13140157  0.08547009]
 [ 0.04822458  0.00257105 -0.00854701]
 [-0.06024599  0.1048572  -0.05128205]]

Few important tips about the program

1. To find the inverse of a matrix, we have used the numpy library in this case.

2. The numpy converts a nested list to a numpy array to perform computations.

3. The .linalg.inv() method takes care of the internal procdedures like finding determinant, multiplying with identity matrix and all that.

 

Python program to find inverse of a matrix snapshot:

python program to find inverse of a matrix without numpy

 


Basic Python Programs
Python Miscellaneous Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :    Published Date : Apr 20,2022  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!