Calculate The Determinant Of A Matrix
Goal¶
This post aims to show how to calculate the determinant of a matrix using numpy i.e., $|A|$
For example, if we have
$$A = \begin{bmatrix} a & b \\ c & d \end{bmatrix} $$Then, $|A|$ is defined as
$$|A| = \begin{vmatrix} a & b \\ c & d \end{vmatrix} = ab - bc $$Reference:
Libraries¶
In [3]:
import numpy as np
Create a matrix¶
In [6]:
a = np.array([[1,2], [3,4]])
a
Out[6]:
Calculate the determinant¶
In [7]:
print(np.linalg.det(a))
In [8]:
a[0, 0] * a[1, 1] - a[0, 1] * a[1, 0]
Out[8]: