docstr: Calculate the inverse of a matrix.
  
  If you want to solve an equation system Ax = b, it's recommended to use
  solve(A, b) instead, it's about 3 times more efficient.
docstr_tok: ["Calculate","the","inverse","of","a","matrix",".","If","you","want","to","solve","an","equation","system","Ax","=","b",",","it","'s","recommended","to","use","solve","(","A",",","b",")","instead",",","it","'s","about","3","times","more","efficient","."]
code: def inverse(ctx, A, **kwargs):
      """
      Calculate the inverse of a matrix.
  
      If you want to solve an equation system Ax = b, it's recommended to use
      solve(A, b) instead, it's about 3 times more efficient.
      """
      prec = ctx.prec
      try:
          ctx.prec += 10
          # do not overwrite A
          A = ctx.matrix(A, **kwargs).copy()
          n = A.rows
          # get LU factorisation
          A, p = ctx.LU_decomp(A)
          cols = []
          # calculate unit vectors and solve corresponding system to get columns
          for i in xrange(1, n + 1):
              e = ctx.unitvector(n, i)
              y = ctx.L_solve(A, e, p)
              cols.append(ctx.U_solve(A, y))
          # convert columns to matrix
          inv = []
          for i in xrange(n):
              row = []
              for j in xrange(n):
                  row.append(cols[j][i])
              inv.append(row)
          result = ctx.matrix(inv, **kwargs)
      finally:
          ctx.prec = prec
      return result
  
imports: from copy import copy
  from ..libmp.backend import xrange
label_desc: Use image node_id 8 for calling the LinearAlgebraMethods obj's underlying member method code with example usage: obj.inverse(ctx, A) and returns: result