Home »
Python »
Linear Algebra using Python
Determinant of a Matrix | Linear Algebra using Python
Linear Algebra using Python | Determinant of a Matrix: Here, we are going to learn about the determinant of a matrix and its implementation in Python.
Submitted by Anuj Singh, on May 29, 2020
In linear algebra, the determinant is a scalar value that can be computed for a square matrix and represents certain properties of the matrix. The determinant of a matrix A is denoted det(A) or det A or |A|. Python library numpy provides a wide range of functions that can be used to manipulate matrices. One of such functions is numpy.linalg.det(A), which allows us to directly return the value of the determinant of a matrix A.
Following is a python code for demonstrating how to use numpy.linalg.det(A)
Python code for demonstrating how to use numpy.linalg.det(A)?
# Linear Algebra Learning Sequence
# Finding determinant
import numpy as np
M = np.array([[2,3,4], [3,45,8], [4,8,78]])
print("---Matrix A---\n", M)
det_A = np.linalg.det(M)
print("The determinant of matrix A : ", det_A)
M = np.array([[2,3,4], [3,14,8], [14,8,7]])
print("\n\n---Matrix B---\n", M)
det_B = np.linalg.det(M)
print("The determinant of matrix B : ", det_B)
Output:
---Matrix A---
[[ 2 3 4]
[ 3 45 8]
[ 4 8 78]]
The determinant of matrix A : 5661.9999999999945
---Matrix B---
[[ 2 3 4]
[ 3 14 8]
[14 8 7]]
The determinant of matrix B : -347.00000000000006