Question

In: Computer Science

inverse a matrix using pseudo inverse using python (numpy can be used) for a 2d list...

inverse a matrix using pseudo inverse using python (numpy can be used) for a 2d list (n x n).

Solutions

Expert Solution

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.


Related Solutions

Create and Compile a Python Script without using Numpy that Generate an nxn matrix using Python...
Create and Compile a Python Script without using Numpy that Generate an nxn matrix using Python Script (ie n=user input) Ask (user input ) and (randomly generated) row and column location Assign Q to (known row and column location ) and 0 to all others location Please show compile script working as well
Develop a python program to - Create a 2D 10x10 numpy array and fill it with...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with the random numbers between 1 and 9 (including 0 and 9). - Assume that you are located at (0,0) (upper-left corner) and want to move to (9,9) (lower-right corner) step by step. In each step, you can only move right or down in the array. - Develop a function to simulate random movement from (0,0) to (9,9) and return sum of all cell values...
Using Python: Normalize a 5x5 random matrix hints: use numpy create a random matrix X apply...
Using Python: Normalize a 5x5 random matrix hints: use numpy create a random matrix X apply Normalization: (X - Mean) / Deviation
Gauss Jordan elimination using python for a 2d list (3x3) without using any library. Thanks
Gauss Jordan elimination using python for a 2d list (3x3) without using any library. Thanks
Using Python coding language (with or without Pandas and/or NumPy), 1. Can you define function sleep...
Using Python coding language (with or without Pandas and/or NumPy), 1. Can you define function sleep to tell whether the participant are of the ages through 18 to 60 and sleep less than 6 hours per day? 2. Develop codes to check whether the sleep function you defined can make correct judgement. Make sure you write comments or create informative vairable name so that I can understand how you check the sleep function. (Hints: You can create toy data/dataframe to...
1 Linear Algebra in Numpy (1) Create a random 100-by-100 matrix M, using numpy method "np.random.randn(100,...
1 Linear Algebra in Numpy (1) Create a random 100-by-100 matrix M, using numpy method "np.random.randn(100, 100)", where each element is drawn from a random normal distribution. (2) Calculate the mean and variance of all the elements in M; (3) Use "for loop" to calculate the mean and variance of each row of M. (4) Use matrix operation instead of "for loop" to calculate the mean of each row of M, hint: create a vector of ones using np.ones(100, 1)?...
Write a python code without using Sympy and Numpy to derive the polynomial 2x2 + 5x...
Write a python code without using Sympy and Numpy to derive the polynomial 2x2 + 5x + 4.
#Python program using loop instead of numpy or pandas. Write a function to enter n student...
#Python program using loop instead of numpy or pandas. Write a function to enter n student scores from 0 to 100 to represent student score, Count how many A (100 - 90), B(89-80), C(79-70), D(69-60), F(<60) We will use numpy array OR pandas later for this problem, for now use loop Invoke the function with 10 student scores, show the result as follow: Test Enter 10 scores Enter a student score: 99 Enter a student score: 88 Enter a student...
Using a system of equations, prove that a 2x2 matrix A has a right inverse if...
Using a system of equations, prove that a 2x2 matrix A has a right inverse if and only if it has a left inverse.
How to write a self-defined function to find the inverse of a matrix by using Gaussian...
How to write a self-defined function to find the inverse of a matrix by using Gaussian Jordan method in MATLAB? Thanks.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT