后浪云Python教程:python怎么求矩阵的逆?

后浪云Python教程:python怎么求矩阵的逆?插图

一.  创建矩阵

没有安装numpy库的,可以执行下面的指令进行安装

pip install numpy

比如我们创建一个3 x 3的矩阵: 

import numpy as np
A = np.mat("1 2 3; 2 3 4; 5 4 6")
print("A\n", A)

二. 计算矩阵的逆

import numpy as np
A = np.mat("1 2 3; 4 5 6; 9 8 10")
print("A\n", A)
inverse = np.linalg.inv(A)
print("inverse: \n", inverse)
THE END