Instagram
youtube
Facebook
Twitter

Compute the Inverse of a NumPy Array

Compute the Inverse of a NumPy Array

Short Description of the Program:
This program calculates the inverse of a square NumPy array using the np.linalg.inv() function from NumPy's linear algebra module.

Explanation:

  • np.array()
    Creates a 2x2 matrix (square array), which is required for inversion.

     
  • np.linalg.inv(array)
    Computes the inverse of the given matrix, provided it is invertible (i.e., its determinant is not zero).

     
  • print()
    Displays both the original matrix and its inverse.

     

Program:

import numpy as np

array = np.array([[4, 7], [2, 6]])

inverse = np.linalg.inv(array)

print("Original Array:\n", array)

print("\nInverse of the Array:\n", inverse)