.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 np
mat_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.0000000000000004
Determinant of 3x3 matrix: 0.9999999999999964

Codebyte Example

The following codebyte example shows the usage of the .det() function:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn Python:NumPy on Codecademy