Created
January 31, 2016 05:15
-
-
Save willhbr/b07395fca62f86ed476c to your computer and use it in GitHub Desktop.
Matrix Determinant Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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