Determinant of a non-square matrix | Linear Algebra using Python

Linear Algebra using Python | Determinant of a non-square matrix: Here, we are going to learn about the determinant of a non-square matrix and its implementation in Python.
Submitted by Anuj Singh, on May 30, 2020

Prerequisites:

Note: Determinant is not defined for a non-square matrix.

In linear algebra, the determinant is a scalar value that can be computed for a square matrix and represents certain properties of the matrix. The determinant of a matrix A is denoted det(A) or det A or |A|. There are non-square matrices which have not defined determinant.

Using python library function, we will try to find the determinant of such a non square matrix.

Python code for demonstrating the determinant of a non-square matrix

# Linear Algebra Learning Sequence
# Determinant of a non-square matrix

import numpy as np 

M = np.array([[2,3,4], [3,45,8]])
print("---Matrix A (2x3)---\n", M)

det_A = np.linalg.det(M)

print("The determinant of matrix A : ", det_A)

M = np.array([[2,3,4], [3,14,8], [14,8,7], [2,2,9]])
print("\n\n---Matrix B (4x3)---\n", M)

det_B = np.linalg.det(M)

print("The determinant of matrix B : ", det_B)

Output:

---Matrix A (2x3)---
 [[ 2  3  4]
 [ 3 45  8]]
Traceback (most recent call last):
  File "main.py", line 9, in <module>
    det_A = np.linalg.det(M)
  File "<__array_function__ internals>", line 5, in det
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/numpy/linalg/linalg.py", line 2113, in det
    _assert_stacked_square(a)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/numpy/linalg/linalg.py", line 213, in _assert_stacked_square
    raise LinAlgError('Last 2 dimensions of the array must be square')
numpy.linalg.LinAlgError: Last 2 dimensions of the array must be square


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.