I am trying to obtain the determinant of a matrix with the help of numpy.linalg.det (matrix) this is the code:
from sympy import *
#from numpy import *
import numpy as np
from matplotlib import *
from py_expression_eval import *
import matplotlib.pyplot as plt
#[1,2] es una fila
#[3,4] otra fila
M = [[1,2], [3,4]]
def matrixDet(matrix):
return np.linalg.det(matrix)
M2 = input("Ingrese la matriz de la forma [1, 2] (esto es una fila), [3, 2] (esto es otra fila)")
print(matrixDet(M2))
the method works if I pass the matrix M but when passing it the matrix M2 does not recognize it even if it passes the same [[1,2], [3,4]]
I get the error:
Traceback (most recent call last):
File "F:/Calculadoras Metodos/matrices/matrixDeterminante.py", line 13, in <module>
print(matrixDet(M2))
File "F:/Calculadoras Metodos/matrices/matrixDeterminante.py", line 11, in matrixDet
return np.linalg.det(matrix)
File "C:\Users\DanielPortatil\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\linalg\linalg.py", line 1817, in det
_assertRankAtLeast2(a)
File "C:\Users\DanielPortatil\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\linalg\linalg.py", line 202, in _assertRankAtLeast2
'at least two-dimensional' % len(a.shape))
numpy.linalg.linalg.LinAlgError: 0-dimensional array given. Array must be at least two-dimensional