简体   繁体   中英

python: how to convert an array into a matrix? with error: AttributeError: 'matrix' object has no attribute 'adjugate'

I want to get the adjugate matrix of a matrix, below is my code.

import numpy as np
from sympy import Matrix

# firt part
a = Matrix(([1,2,0],[0,1,2],[2,0,1]))
a.adjugate()

#second part
a = np.array([[1,2,0], [0,1,2], [2,0,1]])
a = np.matrix(a)
a = a.adjugate() # here is my problem.

After I run this code:

Traceback (most recent call last):
  File "try.py", line 12, in <module>
    a = a.adjugate()
AttributeError: 'matrix' object has no attribute 'adjugate'

The first part of my code can get the adjugate matrix. Why the secondary of my code can not do that?

PS. my original data is an nd array.

You can just replace your a = np.matrix(a) with a = Matrix(a) . It will do for you.

import numpy as np
from sympy import Matrix

# firt part
a = Matrix(([1,2,0],[0,1,2],[2,0,1]))
a.adjugate()

#second part
a = np.array([[1,2,0], [0,1,2], [2,0,1]])
a = Matrix(a)
a = a.adjugate() # here is my problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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