Finding determinant of a square matrix using SciPy library

ScipyScientific ComputingProgramming

The determinant of a matrix, denoted by |A|, is a scalar value that can be calculated from a square matrix. With the help of the determinant of a matrix, we can find the inverse of a matrix and other things that are useful in the systems of linear equations, calculus, etc. The function named scipy.linalg.det() calculates the determinant of a square matrix.

Let’s understand it with the below given examples −


Calculating determinant of 2 by 2 matrix

#Importing the scipy package
import scipy

#Importing the numpy package
import numpy as np

#Declaring the numpy array (Square Matrix)
X = np.array([[5,1],[8,4]])

#Passing the values to scipy.linalg.det() function
M = scipy.linalg.det(X)

#Printing the result
print('Determinant of \n{} \n is {}'.format(X,M))


Determinant of
[[5 1]
[8 4]]
is 12.0


Calculating determinant of 3 by 3 matrix

import scipy
import numpy as np
Y = np.array([[1,2,9],[5,4,3],[1,5,3]])
M = scipy.linalg.det(Y)
print('Determinant of \n{} \n is {}'.format(Y,M))


Determinant of
[[1 2 9]
[5 4 3]
[1 5 3]]
is 162.0
Updated on 24-Nov-2021 10:35:59