简体   繁体   English

在python中将矩阵转换为梯形

[英]Converting matrix to echelon form at python

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.我只想将 3x3 矩阵转换为梯形。 TypeError: 'int' object is not iterable and sometimes AttributeError: 'list' object has no attribute 'rref' TypeError:“int”对象不可迭代,有时 AttributeError:“list”对象没有属性“rref”

Just convert your matrix to a SymPy Matrix , like this:只需将您的matrix转换为 SymPy Matrix ,如下所示:

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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM