使用 SciPy 庫計算方陣的行列式
矩陣的行列式,表示為 |A|,是一個可以從方陣計算出的標量值。藉助矩陣的行列式,我們可以求出矩陣的逆以及在方程組、微積分等方面實用的其他內容。scipy.linalg.det() 命名的函式用於計算方陣的行列式。
讓我們透過以下給定的示例理解一下這一點 −
示例
計算 2 × 2 矩陣的行列式
#Importing the scipy package
import scipy
#Importing the numpy package
import numpy as np
#Declaring the numpy array (Square Matrix)
X = np.array([[5,1],[8,4]])
#Passing the values to scipy.linalg.det() function
M = scipy.linalg.det(X)
#Printing the result
print('Determinant of
{}
is {}'.format(X,M))輸出
Determinant of [[5 1] [8 4]] is 12.0
示例
計算 3 × 3 矩陣的行列式
import scipy
import numpy as np
Y = np.array([[1,2,9],[5,4,3],[1,5,3]])
M = scipy.linalg.det(Y)
print('Determinant of
{}
is {}'.format(Y,M))輸出
Determinant of [[1 2 9] [5 4 3] [1 5 3]] is 162.0
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP