是否有一种方法可以对矩阵进行列(或行)操作?例如,矩阵的每一列除以它的范数,或者矩阵的每一行乘以它的范数?
可以使用row_op
和col_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]])