python 矩阵的操作(逆,转置,行列式,特征值和特征向量,解方程组)

import numpy as np
from numpy.linalg import *

lst= np.eye(3)
print(lst)
'''
[[ 1.  0.  0.]
 [ 0.  1.  0.]
 [ 0.  0.  1.]]
'''
lst1=np.array([[1,2],[3,4]])

# 矩阵的逆
print(inv(lst1))
# print(lst.invent)
'''
[[-2.   1. ]
 [ 1.5 -0.5]]
'''

# 转置矩阵
print(lst1.transpose())
'''
[[1 3]
 [2 4]]
'''

# 行列式
print(det(lst1))   # -2.0  determinant

# 特征值和特征向量
print(eig(lst1))   # eigenvalue
'''                 第一个元祖是特征值,第二个为对应的特征向量
(array([-0.37228132,  5.37228132]), array([[-0.82456484, -0.41597356],
       [ 0.56576746, -0.90937671]]))
'''

y = np.array([[5.],[7.]])         # 解方程组  注意括号

print(solve(lst1,y))
'''
[[-3.]
 [ 4.]]
'''
原文地址:https://www.cnblogs.com/hanbb/p/7604081.html