Home > Blockchain >  Converting matrix to echelon form at python
Converting matrix to echelon form at python

Time:05-19

from sympy import *

matrix = []
print("Enter the entries of the 3x3 matrix:")

for i in range(0,3):
    a =[]
    for j in range(0,3):
         a.append(int(input()))
    matrix.append(a)

for i in range(0,3):
    for j in range(0,3):
        print(matrix[i][j], end = " ")
    print()
    
for i in range(0,3):
    for j in range(0,3):
        M[i][j]=list(matrix[i][j])

M_rref = M.rref()
print("The Row echelon form of matrix M and the pivot columns : {}".format(M_rref))

I have a error when I transferring arrays to each other. I just wanna convert the 3x3 matrix into echelon form. TypeError: 'int' object is not iterable and sometimes AttributeError: 'list' object has no attribute 'rref'

CodePudding user response:

Just convert your matrix to a SymPy Matrix, like this:

from sympy import *

matrix = []
print("Enter the entries of the 3x3 matrix:")

for i in range(0,3):
    a =[]
    for j in range(0,3):
         a.append(int(input()))
    matrix.append(a)

for i in range(0,3):
    print(matrix[i])

M = Matrix(matrix)
M_rref = M.rref()
print("The Row echelon form of matrix M and the pivot columns : {}".format(M_rref))
  • Related