Search code examples
pythonmatrixsympy

Inverse of a matrix in SymPy?


I was wondering how to create a matrix and compute its inverse using SymPy in Python?

For example, for this symbolic matrix:


Solution

  • If your question was: How to compute the inverse of a matrix M in sympy then:

    M_inverse = M.inv()
    

    As for how to create a matrix:

    M = Matrix(2,3, [1,2,3,4,5,6])
    

    will give you the following 2X3 matrix:

    1 2 3

    4 5 6

    See: http://docs.sympy.org/0.7.2/modules/matrices/matrices.html