使用 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