VOOZH about

URL: https://www.geeksforgeeks.org/numpy/how-to-inverse-a-matrix-using-numpy/

⇱ How to Inverse a Matrix using NumPy - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Inverse a Matrix using NumPy

Last Updated : 14 Jan, 2026

Matrix inversion is the process of finding a matrix that reverses the effect of another matrix during multiplication. NumPy provides efficient functions to compute the inverse of a matrix, making it easy to solve systems of equations and perform linear algebra operations.

The inverse of a matrix exists only if the matrix is non-singular i.e., the determinant should not be 0. Using determinant and adjoint, we can easily find the inverse of a square matrix using the below formula:

if det(A) != 0:
A_inv = adj(A) / det(A)
else:
print("Inverse doesn't exist")

Matrix Equation:

where,
A-1: The inverse of matrix A
x: The unknown variable column
B: The solution matrix

Inverse Matrix using NumPy

numpy.linalg.inv() in the NumPy module is used to compute the inverse matrix in Python.

Syntax:

numpy.linalg.inv(a)

  • Parameters: a - Matrix to be inverted
  • Returns: Inverse of the matrix a.

Example 1:

This example creates a 3×3 NumPy matrix and finds its inverse using np.linalg.inv()


Output
[[ 0.17647059 -0.00326797 -0.02287582]
 [ 0.05882353 -0.13071895 0.08496732]
 [-0.11764706 0.1503268 0.05228758]]

Example 2:

This example creates a 4×4 NumPy matrix and computes its inverse using np.linalg.inv()


Output
[[ 0.13368984 0.10695187 0.02139037 -0.09090909]
 [-0.00229183 0.02673797 0.14820474 -0.12987013]
 [-0.12987013 0.18181818 0.06493506 -0.02597403]
 [ 0.11000764 -0.28342246 -0.11382735 0.233766...

Example 3:

This example computes the inverses of multiple NumPy matrices using np.linalg.inv()


Output
[[[-2. 1. ]
 [ 1.5 -0.5 ]]

 [[-1.25 0.75]
 [ 0.75 -0.25]]]
Comment
Article Tags:
Article Tags:

Explore