Skip to content
CampusEduX

Problem 4: Calculate a Matrix's Inverse and Verify It

Easypython
Learn the Concept: NumPy (Condensed Reference)

Problem Description

Write a Python program that calculates the inverse of a 2x2 matrix using np.linalg.inv(), then verifies the result by multiplying the original matrix by its inverse (which should produce the identity matrix).

Input

A 2x2 matrix.

Output

The inverse matrix, and the verification result (should be the identity matrix).

Constraints

  • The matrix must be invertible (non-zero determinant).

Example Input

text
[[2,0],[0,4]]

Example Output

text
Inverse: [[0.5, 0.], [0., 0.25]] Verification (should be identity): [[1., 0.], [0., 1.]]

Concepts Covered

np.linalg.inv(), np.matmul(), identity matrix verification.

Related Problems

  • Problem 1: Generate Reproducible Random Data
    Easy · python
    Solve Problem
  • Problem 2: Filter Data Using Boolean Masking
    Easy · python
    Solve Problem
  • Problem 3: Select Specific Elements Using Fancy Indexing
    Easy · python
    Solve Problem

Input (stdin)

Output

Run your code to see output here...