我希望在sympy中进行矩阵计算后,将提取的公共因子放在矩阵外部显示。
我编写了以下代码。
我得到了以下输出。
我尝试使用 collect(A,exp(I*a)),但出现了以下错误。
我编写了以下代码。
from sympy import *
a = symbols("a")
b = symbols("b")
A = Matrix([exp(I*a),exp(I*a)*exp(I*b)])
print simplify(A)
我得到了以下输出。
Matrix([
[ exp(I*a)],
[exp(I*(a + b))]])
然而,我想得到以下输出。
exp(I*a)*Matrix([
[ 1],
[exp(I*b)]])
我尝试使用 collect(A,exp(I*a)),但出现了以下错误。
Traceback (most recent call last):
File "<ipython-input-65-834f4c326df4>", line 1, in <module>
runfile('C:/Anaconda2/Programs/test/untitled44.py', wdir='C:/Anaconda2/Programs/test')
File "C:\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile
execfile(filename, namespace)
File "C:\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Anaconda2/Programs/test/untitled44.py", line 14, in <module>
collect(A,exp(I*a))
File "C:\Anaconda2\lib\site-packages\sympy\simplify\simplify.py", line 451, in collect
if expr.is_Mul:
File "C:\Anaconda2\lib\site-packages\sympy\matrices\matrices.py", line 3084, in __getattr__
"%s has no attribute %s." % (self.__class__.__name__, attr))
AttributeError: MutableDenseMatrix has no attribute is_Mul.
我知道一种方法可以提取矩阵元素的公共因子,类似于以下链接。 https://github.com/sympy/sympy/issues/8442
但这不是我的愿望。
我该怎么办?