The Wayback Machine - https://web.archive.org/web/20240119133038/https://www.geeksforgeeks.org/how-to-calculate-the-determinant-of-a-matrix-using-numpy/
Open In App
Related Articles

How to Calculate the determinant of a matrix using NumPy?

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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




# importing Numpy package
import numpy as np
  
# creating a 2X2 Numpy matrix
n_array = np.array([[50, 29], [30, 44]])
  
# Displaying the Matrix
print("Numpy Matrix is:")
print(n_array)
  
# calculating the determinant of matrix
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




# importing Numpy package
import numpy as np
  
# creating a 3X3 Numpy matrix
n_array = np.array([[55, 25, 15],
                    [30, 44, 2],
                    [11, 45, 77]])
  
# Displaying the Matrix
print("Numpy Matrix is:")
print(n_array)
  
# calculating the determinant of matrix
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




# importing Numpy package
import numpy as np
  
# creating a 5X5 Numpy matrix
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]])
  
# Displaying the Matrix
print("Numpy Matrix is:")
print(n_array)
  
# calculating the determinant of matrix
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.


Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 05 Sep, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials