Here, we will learn to write the code for the inverse of a matrix.

We will use numpy.linalg.inv() function to find the inverse of a matrix.

If we multiply the inverse matrix with its original matrix then we get the identity matrix.

    Algorithm:

  1. Import the package numpy.
  2. An array is initialized using numpy and stored in variable x.
  3. The array is inversed using the function numpy.linalg.inv(x) .
  4. Inversed array is stored in variable y.
  5. Now we’ll print both array x and y.
  6. Exit 

Code:

import numpy

x=numpy.array([[1,2], [3,4]])

y=numpy.linalg.inv(x)

print(x)

print (y)

 

Output:

[[1 2]

 [3 4]]


[[-2.   1. ]

 [ 1.5 -0.5]]

 

Report Error/ Suggestion

Related Posts:

[yuzo_views]











CopyRight © 2019

CopyRight © 2019