

I have the following error.  
AttributeError: the object 'list' has no attribute 'bags'  
Tell me how to produce as follows.  
Matrix ([[-4, 1, 9], [1, 2, -4], [2, -3, 6]])

[code]

    from sympy import *
    var('myMatrix')
    mylist=[[0]*3]*3e
    mylist[0]=[-4, 1, 9]
    mylist[1]=[1, 2, -4]
    mylist[2]=[2, -3, 6]
    myMatrix=Matrix()
    for i in range(len(mylist)):
        print(mylist[i])
        myMatrix = myMatrix.row_insert(i-1, mylist[i])
    print("# ",myMatrix)
    
[/code]


CC BY-SA 4.0
2021-05-18T06:44:04.420
75915
2021-05-18T06:47:53.483
45343
question
python
Please tell me how to use Matrix.row_insert in sympy


I get an error when I try to insert a list with row_insert.  
Rewriting two places as below should work.

[code]

    from sympy import *
    var('myMatrix')
    mylist=[[0]*3]*3  # FIX
    mylist[0]=[-4, 1, 9]
    mylist[1]=[1, 2, -4]
    mylist[2]=[2, -3, 6]
    myMatrix=Matrix()
    for i in range(len(mylist)):
        print(mylist[i])
        myMatrix = myMatrix.row_insert(i, Matrix([mylist[i]])) # FIX
    
    print("# ",myMatrix)
    
[/code]


CC BY-SA 4.0
2021-05-18T06:47:53.483
75916
2021-05-18T06:47:53.483
45371
75915
answer