NumPy Tutorial NumPy Statistics NumPy References

NumPy - linalg.det() function



The NumPy linalg.det() function is used to compute the determinant of an array. The syntax for using this function is given below:

Syntax

numpy.linalg.det(a)

Parameters

a Required. Specify an array to compute determinants for.

Return Value

Returns determinant of a.

Example: determinant of a matrix

In the example below, linalg.det() function is used to calculate determinant of the given matrix.

import numpy as np
Arr = np.array([[10,20],[30, 40]])

print("Array is:")
print(Arr)

#calculating determinant values
print("\nDeterminant is:", np.linalg.det(Arr))

The output of the above code will be:

Array is:
[[10 20]
 [30 40]]

Determinant is: -200.0000000000001

Example: determinants for a stack of matrices

The function can also be used to calculate the determinants for a stack of matrices. Consider the following example.

import numpy as np
Arr = np.array([ [[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]] ])

#calculating determinant values
print("\nDeterminant is:", np.linalg.det(Arr))

The output of the above code will be:

Determinant is:[-2. -3. -8.]

❮ NumPy - Functions