← Back to NumPy Course | Chapter 7: Linear Algebra | Lesson 1 of 6

np.linalg.det()

The determinant is a single number that tells you whether a square matrix can be inverted and how it scales area.

In this page:

  1. np.linalg.det()
Syntax
python
det = np.linalg.det(matrix)

np.linalg.det()

np.linalg.det computes the determinant of a square matrix. A determinant of zero means the matrix is singular and has no inverse. Floating-point results may show tiny rounding errors, so round when printing.

Note: For a 2x2 matrix [[a, b], [c, d]] the determinant is a*d - b*c.

Example: np.linalg.det()

python
import numpy as np

A = np.array([[4, 3], [6, 3]])
print(np.linalg.det(A).round(2))
S = np.array([[1, 2], [2, 4]])
print(np.linalg.det(S).round(2))

# Output:
# -6.0
# 0.0
Related Topics
Common Mistakes
  1. Calling det on a non-square matrix
  2. Comparing det == 0 exactly with floats
  3. Confusing determinant with trace
Chapter Summary
  • det works on square matrices
  • Zero determinant means singular
  • Round float results
  • 2x2 formula is ad - bc
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.