How to Calculate the determinant of a matrix using NumPy?
Last Updated :
05 Sep, 2020
A special number that can be calculated from a square matrix is known as the Determinant of a square matrix. The Numpy provides us the feature to calculate the determinant of a square matrix using numpy.linalg.det() function.
Syntax:
numpy.linalg.det(array)
Example 1: Calculating Determinant of a 2X2 Numpy matrix using numpy.linalg.det() function
Python3
import numpy as np
n_array = np.array([[ 50 , 29 ], [ 30 , 44 ]])
print ( "Numpy Matrix is:" )
print (n_array)
det = np.linalg.det(n_array)
print ( "\nDeterminant of given 2X2 matrix:" )
print ( int (det))
|
Output:
In the above example, we calculate the Determinant of the 2X2 square matrix.
Example 2: Calculating Determinant of a 3X3 Numpy matrix using numpy.linalg.det() function
Python3
import numpy as np
n_array = np.array([[ 55 , 25 , 15 ],
[ 30 , 44 , 2 ],
[ 11 , 45 , 77 ]])
print ( "Numpy Matrix is:" )
print (n_array)
det = np.linalg.det(n_array)
print ( "\nDeterminant of given 3X3 square matrix:" )
print ( int (det))
|
Output:
In the above example, we calculate the Determinant of the 3X3 square matrix.
Example 3: Calculating Determinant of a 5X5 Numpy matrix using numpy.linalg.det() function
Python3
import numpy as np
n_array = np.array([[ 5 , 2 , 1 , 4 , 6 ],
[ 9 , 4 , 2 , 5 , 2 ],
[ 11 , 5 , 7 , 3 , 9 ],
[ 5 , 6 , 6 , 7 , 2 ],
[ 7 , 5 , 9 , 3 , 3 ]])
print ( "Numpy Matrix is:" )
print (n_array)
det = np.linalg.det(n_array)
print ( "\nDeterminant of given 5X5 square matrix:" )
print ( int (det))
|
Output:
In the above example, we calculate the Determinant of the 5X5 square matrix.
Share your thoughts in the comments
Please Login to comment...