Skip to content

Instantly share code, notes, and snippets.

@willhbr
Created January 31, 2016 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willhbr/b07395fca62f86ed476c to your computer and use it in GitHub Desktop.
Save willhbr/b07395fca62f86ed476c to your computer and use it in GitHub Desktop.
Matrix Determinant Calculator
def calculate(mat, mul=1):
return (mul * mat[0][0] if len(mat) == 1 else sum((mul * calculate(list(map(lambda j: list(filter(lambda el: el != None, (mat[j][k] if k != i else None for k in range(len(mat))))), range(1, len(mat)))), (-1 if i % 2 == 0 else 1) * mat[0][i])) for i in range(len(mat))))
matrix = [
[1, -2, 3],
[0, -3, -4],
[0, 0, -3]
]
print(calculate(matrix))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment