python矩阵运算可以用numpy模块,也可以用scipy模块,主要运算包括以下几种:
搬运:Python3 矩阵求最简行阶梯矩阵
import numpy as np from sympy import Matrix from sympy.matrices import dense # Matrix convert to array A_mat = Matrix([[1, 2, 1, 1], [2, 1, -2, -2], [1, -1, -4, 3]]) A_arr1 = np.array(A_mat.tolist()).astype(np.int32) A_arr2 = dense.matrix2numpy(A_mat, dtype=np.int32) # array convert to Matrix B_arr = np.array([[1, 2, 1, 1], [2, 1, -2, -2], [1, -1, -4, 3]]) B_mat = Matrix(B_arr) # RREF A_rref = np.array(A.rref()[0].tolist()).astype(np.int32) B_rref = (Matrix(B_arr).rref()[0].tolist()).astype(np.int32)