You can use the package NumPy
, who owns a wide collection of functions mathematics capable of working with multidimensional matrices.
To compute the determinant of a matrix you can use the function numpy.linalg.det()
, look at you:
import numpy
matriz = [ [1, 1, 1], [2, 2, 2], [3, 3, 3] ]
print( numpy.linalg.det( matriz ) )
See working on Repl.it
To read the matrix from a file and calculate its determinant:
import numpy
matriz = []
with open('matriz.txt', 'r') as f:
for linha in f.readlines():
matriz.append( [ float(i) for i in linha.split() ] )
determ = numpy.linalg.det( matriz )
print(matriz)
print(determ)
See working on Repl.it.
Or, simply:
import numpy
with open('matriz.txt', 'r') as f:
matriz = [[ float(i) for i in linha.split()] for linha in f.readlines()]
determ = numpy.linalg.det( matriz )
print(matriz)
print(determ)
See working on Repl.it.
Could post the contents of the input file
matriz.txt
also ?– Lacobus
would be a file like this 10#10#10
– Pisadiasi