×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Inverse of a Matrix | Linear Algebra using Python

Linear Algebra using Python | Inverse of a Matrix: Here, we are going to learn about the inverse of a matrix and its implementation in Python.
Submitted by Anuj Singh, on June 03, 2020

Prerequisites:

Syntax:

    inv_M = numpy.linalg.inv(M)

Here, "M" is the matrix.

Python code to find the inverse of a matrix

# Linear Algebra Learning Sequence
# Inverse of a Matrix

import numpy as np

M = np.array([[2,3,4], [3,45,8], [4,8,78]])
print("---Matrix A---\n", M)

ai = np.linalg.inv(M) 
print('\n\nInverse of A as ----\n', ai)

Output:

---Matrix A---
 [[ 2  3  4]
 [ 3 45  8]
 [ 4  8 78]]


Inverse of A as ----
 [[ 0.60861886 -0.03567644 -0.0275521 ]
 [-0.03567644  0.02472625 -0.00070646]
 [-0.0275521  -0.00070646  0.0143059 ]]
Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.