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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.