使用 SciPy 庫求解方陣的逆矩陣
SciPy 庫具有 scipy.linalg.inv() 函式,用於求解方陣的逆矩陣。讓我們瞭解一下如何使用此函式計算矩陣的逆矩陣 −
示例
2x2 矩陣的逆矩陣
#Importing the scipy package
import scipy.linalg
#Importing the numpy package
import numpy as np
#Declaring the numpy array (Square Matrix)
A = np.array([[3, 3.5],[3.2, 3.6]])
#Passing the values to scipy.linalg.inv() function
M = scipy.linalg.inv(A)
#Printing the result
print('Inverse of
{}
is {}'.format(A,M))輸出
Inverse of [[3. 3.5] [3.2 3.6]] is [[-9. 8.75] [ 8. -7.5 ]]
示例
3x3 矩陣的逆矩陣
import scipy
import numpy as np
A = np.array([[2,1,-2],[1,0,0],[0,1,0]])
M = scipy.linalg.inv(A)
print('Inverse of
{}
is {}'.format(A,M))輸出
Inverse of [[ 2 1 -2] [ 1 0 0] [ 0 1 0]] is [[ 0. 1. 0. ] [ 0. -0. 1. ] [-0.5 1. 0.5]]
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP