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 ]]


Comments and Discussions!

Load comments ↻





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