In: Computer Science
: Find the inverse of the three matrices listed below. The code should prompt the user to input the size of the matrix and to put the value of each element in the matrix. The output should contain the solution to the inverse from using a function created by you, and the solution found using the NumPy package.
I1 = [ 1 2 3 4]−1
I2 = [ 1 2 3 4 5 6 7 2 9 ] −1
I3 =[ 1 3 5 9 1 3 1 7 4 3 9 7 5 2 0 9 ] −1
""" Python program for inverse of matrix """ import numpy as np def getInverse(matrix): try: inverse = np.linalg.inv(matrix) except np.linalg.LinAlgError: print('Inverse does not exist') pass else: print('Inverse of matrix -') print(inverse) def main(): R,C = map(int, input("Enter size of matrix: ").split()) print("Enter matrix({},{}): ".format(R,C), end='') entries = list(map(int, input().split())) matrix = np.array(entries).reshape(R, C) print(matrix) getInverse(matrix) if __name__ == '__main__': main() # Program ends here