(ctx, A)
Calculate the determinant of a matrix.
Calculate the determinant of a matrix.
Calculate the determinant of a matrix .
def det(ctx, A):
        """
        Calculate the determinant of a matrix.
        """
        prec = ctx.prec
        try:
            # do not overwrite A
            A = ctx.matrix(A).copy()
            # use LU factorization to calculate determinant
            try:
                R, p = ctx.LU_decomp(A)
            except ZeroDivisionError:
                return 0
            z = 1
            for i, e in enumerate(p):
                if i != e:
                    z *= -1
            for i in xrange(A.rows):
                z *= R[i,i]
            return z
        finally:
            ctx.prec = prec
def det ( ctx , A ) : prec = ctx . prec try : # do not overwrite A A = ctx . matrix ( A ) . copy ( ) # use LU factorization to calculate determinant try : R , p = ctx . LU_decomp ( A ) except ZeroDivisionError : return 0 z = 1 for i , e in enumerate ( p ) : if i != e : z *= - 1 for i in xrange ( A . rows ) : z *= R [ i , i ] return z finally : ctx . prec = prec