NumPy – Determinant

NumPy - Determinant

In this chapter, we will discuss about NumPy – Determinant. The determinant is a very useful value in linear algebra. It is calculated from the diagonal elements of a square matrix. For a 2×2 matrix, it is simply the subtraction of the product of the top left and bottom right element from the product of the other two.

In other words, for a matrix [[a,b], [c,d]], the determinant is computed as ‘ad-bc’. The larger square matrices are considered to be a combination of 2×2 matrices.

The numpy.linalg.det() function calculates the input matrix.

import numpy as np
a = np.array([[1,2], [3,4]]) 
print np.linalg.det(a)

It will output −

-2.0

Example Of NumPy – Determinant

import numpy as np 

b = np.array([[6,1,1], [4, -2, 5], [2,8,7]]) 
print b 
print np.linalg.det(b) 
print 6*(-2*7 - 5*8) - 1*(4*7 - 5*2) + 1*(4*8 - -2*2)

It will output −

[[ 6 1 1]
 [ 4 -2 5]
 [ 2 8 7]]

-306.0

-306

Next TopicClick Here

This Post Has 2 Comments

Leave a Reply