OKPEDIA PYTHON MATRIX

How to find the determinant of a matrix in Python

To calculate the determinant of a matrix in Python we use the function linalg.det() of the NumPy module

import numpy as np
np.linalg.det(M)

The parameter M is a square matrix.

Example

Define a square matrix

import numpy as np
M=np.array([[1,2],[3,4]])

To calculate the determinant of the matrix use the function linalg.det()

d=np.linalg.det(M)
print(d)

The output is the determinant of the matrix

-2The determinant of the matrix is -2

https://how.okpedia.org/en/python/how-to-find-the-determinant-of-a-matrix-in-python


Report us an error or send a suggestion to improve this page


Matrix in Python


FacebookTwitterLinkedinLinkedin