[英]Column-wise (or row-wise) operations on matrices in sympy
Is there a way to do column-wise (or row-wise) operations on matrices in sympy?有没有办法对 sympy 中的矩阵进行按列(或按行)的操作? For example, dividing each column of a matrix by its norm, or multiplying each row of a matrix by its norm?
例如,将矩阵的每一列除以其范数,或将矩阵的每一行乘以其范数?
You can use row_op
and col_op
.您可以使用
row_op
和col_op
。 From the documentation for row_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)``.
These methods act in-place:这些方法就地起作用:
>>> a = Matrix([[1, 2], [3, 4]])
>>> a.row_op(1, lambda i, j: i*2)
>>> a
Matrix([
[1, 2],
[6, 8]])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.