我正在寻找一种访问sypy矩阵元素以执行行操作的方法,但似乎找不到这样做的方法,也找不到任何描述该过程的现有文档。在
例如,假设我有以下代码:
import sympy as sp
from sympy import *
matrix = sp.Matrix([[3,2,2],[1,2,3]])
我想划分第一行和第二列中的元素,在本例中是2。我能想到的一个非常老套的方法是:
^{pr2}$但现在矩阵的第一行是
[3/2,1,1]
这次我想把这行再除以3/2,我之前的方法不适用。如何执行这些行操作,以及如何让它们更新原始矩阵?(即,当我将一行除以3时,它会更新原始矩阵中的行,而不仅仅返回一个单独的矩阵,只反映更新的行)
矩阵r1与sympe交换有何方法?在
编辑:
我发现我可以通过简单地使用matrix[row#,:]/matrix[row#,column#]
来完成问题的除法部分,但是我仍然不确定如何将这个行操作直接反映在原始矩阵中,或者如何进行行交换。在
当我遇到这样的问题时,我会尝试搜索目录以获得帮助:
所以看起来两者都可以用。在
^{pr2}$或者
我还是一个
sympy
新手,但对numpy
很熟悉。所以让我们看看sympy
的行为方式是否大致相同。在在
isympy
会话中:这是一个浮点除法;我怀疑用一个不同的除数,我可以做一个正确的分数除法。在
^{pr2}$相关问题 更多 >
编程相关推荐