.det()
Published Apr 12, 2024
Contribute to Docs
In NumPy, the .det()
function computes the determinant of a square matrix. It’s worth noting that this function is specifically intended to be used with square matrices, which have an equal number of rows and columns.
Syntax
numpy.linalg.det(array)
array
: The array for which the determinant is to be computed.
Example
The following example demonstrates the use of the .det()
function:
import numpy as npmat_2x2 = np.array([[1, 2], [3, 4]])det_mat_2x2 = np.linalg.det(mat_2x2)print("Determinant of 2x2 matrix:", det_mat_2x2)mat_3x3 = np.array([[1, 2, 3], [0, 1, 4], [5, 6, 0]])det_mat_3x3 = np.linalg.det(mat_3x3)print("Determinant of 3x3 matrix:", det_mat_3x3)
The above code produces the following output:
Determinant of 2x2 matrix: -2.0000000000000004Determinant of 3x3 matrix: 0.9999999999999964
Codebyte Example
The following codebyte example shows the usage of the .det()
function:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:NumPy on Codecademy
- Career path
Data Scientist: Machine Learning Specialist
Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.Includes 27 CoursesWith Professional CertificationBeginner Friendly90 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours