sympy 中矩阵的按列(或按行)操作

Column-wise (or row-wise) operations on matrices in sympy

有没有办法在 sympy 中对矩阵进行列式(或行式)操作?比如矩阵的每一列除以它的范数,或者矩阵的每一行乘以它的范数?

您可以使用 row_opcol_op。来自 row_op 的文档:

row_op(i, f) method of sympy.matrices.dense.MutableDenseMatrix instance
    In-place operation on row ``i`` using two-arg functor whose args are
    interpreted as ``(self[i, j], j)``.

这些方法就地起作用:

>>> a = Matrix([[1, 2], [3, 4]])
>>> a.row_op(1, lambda i, j: i*2)
>>> a
Matrix([
[1, 2],
[6, 8]])