import numpy as np import scipy from scipy import linalg # 1. 求解Ax = b A = np.array([[3, 1],
[1, 2]]) b = np.array([9, 8]) x = np.linalg.solve(A, b) print(x)
# 2. 常用方法 A = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) I = np.eye(3) # 单位矩阵 A.T # A的转置
3 * A # 普通乘 np.dot(A, I) # 矩阵乘法 np.linalg.inv(A) # A的逆 # 3. A的LU分解(有时并不标准L) L, U = scipy.linalg.lu(A, True) print(L) print(U)