【Python】SymPy库——关于矩阵的高级操作

本文探讨了Python的SymPy库在矩阵高级操作中的应用,包括如何进行高效计算,例如展示了一个低成本的矩阵操作示例:(lamda - 5)**2*(lamda - 3)*(lamda + 2)。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import sympy as sp

# 求determinant---行列式
matrix_A = sp.Matrix([[1, 2, 3], [4, 6, 8], [7, 3, 2]])
determinant = matrix_A.det()

# 求rref---行最简形
matrix_B = sp.Matrix([[1, 0, 1, 3], [2, 3, 4, 7], [-1, -3, -3, -4]])
rrefMatrix = matrix_B.rref()
# tuple的第二个元素是pivot Column

# 求零空间 Nullspace of a matrix.
# returns a list of column vectors that span the nullspace of the matrix.
matrix_C = sp.Matrix([[1, 2, 3, 0, 0], [4, 10, 0, 0, 1]])
nullSpace = matrix_C.nullspace()

# 求列空间 columnspace of a matrix.
# columnspace returns a list of column vectors that span the columnspace of the matrix.
matrix_D = sp.Matrix([[1, 1, 2], [2, 1, 3], [3, 1, 4]])
colSpace = matrix_D.columnspace()

#  求特征值 eigenvalues of a matrix.
#  eigenvals returns a dictionary of eigenvalue: algebraic_multiplicity pairs (similar to the output of roots).
matrix_E = sp.Matrix([[3, -2, 4, -2], [5, 3, -3, -2],
                      [5, -2, 2, -2], [5, -2, -3, 3]])
matrix_E.eigenvals()
注意:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值