python矩陣的運算大全
python矩陣運算可以用numpy模塊,也可以用scipy模塊,主要運算包括以下幾種:
#1-1python矩陣運算所需模塊
import numpy as np
import matplotlib.pyplot as plt
import scipy.linalg as lg #scipy矩陣運算模塊
#1-2定義矩陣和進行相關的矩陣運算
a=np.array([[1,2],[3,4]]) #定義原始矩陣
print(a)
print(lg.inv(a)) #求取矩陣的逆矩陣
print(lg.det(a)) #求取矩陣的行列式
b=np.array([6,14]) #定義線性方程組的結果向量
print(lg.solve(a,b)) #求解線性方程組的解
print(lg.eig(a)) #求取矩陣的特征值與特征向量
print("LU:",lg.lu(a)) #矩陣的LU分解
print("QR:",lg.qr(a)) #矩陣的QR分解
print("SVD:",lg.svd(a)) #矩陣的奇異值分解(SVD分解)
print("Schur:",lg.schur(a)) #矩陣的Schur分解
希望對大家的矩陣運算有所幫助!!!