Speed up python code for computing matrix cofactors

前端 未结 4 1666
庸人自扰
庸人自扰 2021-01-05 00:40

As part of a complex task, I need to compute matrix cofactors. I did this in a straightforward way using this nice code for computing matrix minors. Here is my code:

4条回答
  •  青春惊慌失措
    2021-01-05 01:17

    from sympy import *
    A = Matrix([[1,2,0],[0,3,0],[0,7,1]])
    A.adjugate().T
    

    And the output (which is cofactor matrix) is:

    Matrix([
    [ 3, 0,  0],
    [-2, 1, -7],
    [ 0, 0,  3]])
    

提交回复
热议问题