有没有办法在同义词中对矩阵进行逐列(或逐行)操作?例如,将矩阵的每一列除以其范数,或将矩阵的每一行乘以其范数?
答案 0 :(得分:2)
您可以使用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]])