In: Computer Science
inverse a matrix using pseudo inverse using python (numpy can be used) for a 2d list (n x n).
Source Code:
import numpy as np
n = int(input('Enter the value of n:'))
matrix = []
for _ in range(n):
matrix.append([])
for i in range(n):
for j in range(n):
print('Enter the value for matrix[',i+1,']','[',j+1,']:',end = '
')
val = int(input())
matrix[i].append(val)
invMatrix = np.linalg.pinv(matrix)
print('Input Matrix ... ')
print(matrix)
print('Inverted Matrix ... ')
print(invMatrix)
Output:
Please appreciate the solution if you find it helpful.
If you have any doubts in the solution, feel free to ask me in the comment section.