Python – scipy.linalg.inv


scipy.linalg 包含大量用于线性代数的不同功能。其中之一是 inv() 函数,用于求解方阵的逆矩阵。

语法

scipy.linalg.inv(x)

其中 x 为一个方阵。

实例 1

我们考虑下面的实例:

Open Compiler
# Import the required libraries from scipy import linalg import numpy as np # defines the array a = np.array([[5, 3], [6, 4]]) print("Input matrix :", a) # Finding the inverse of a square matrix x = linalg.inv(a) print(" Inverse of Square Matrix A :", x)

Learn Python in-depth with real-world projects through our Python certification course. Enroll and become a certified expert to boost your career.

输出

上面的程序将生成以下输出:

Input matrix :
[[5 3]
[6 4]]

Inverse of Square Matrix A :
[[ 2. -1.5]
[-3. 2.5]]

实例 2

我们再看另一个实例:

Open Compiler
# Import the required libraries from scipy import linalg import numpy as np # defines the matrix q = np.array([[[5., 6.], [7., 8.]], [[2, 4], [6, 8]]]) print("Input matrix :", q) # Finding the inverse of the square matrix m = np.linalg.inv(q) print(" Inverse of the Square Matrix Q :", m)

输出

上面的程序将生成以下输出:

Input matrix :
[[[5. 6.]
[7. 8.]]

[[2. 4.]
[6. 8.]]]

Inverse of the Square Matrix Q :
[[[-4. 3. ]
[ 3.5 -2.5 ]]

[[-1. 0.5 ]
[ 0.75 -0.25]]]

更新于: 2021 年 12 月 22 日

329 次浏览

开始你的 职业

参加完课程并获得认证

开始
广告