[英]WolframClient in Python: how to convert the output of wolframclient.evaluate into a sympy expression?
我在 Python 中使用 wolframclient,在我计算的某个点上,我有一个 output,如下所示
(Plus[-9, Times[2, Power[Global`y, 4]]], Plus[Times[3, Global`x], Times[-2, Power[Global`y, 3]]])
现在我需要将这个 output 转换成 sympy 格式,比如
[-9 + 2*y**4, 3*x - 2*y**3]
有没有办法做到这一点?
谢谢,卢卡
Mathematica 解析器似乎不喜欢元组,因此如果您可以将两部分分开并将“Global`”替换为 null 字符串,它就可以工作:
>>> a = 'Plus[-9, Times[2, Power[Global`y, 4]]]'
>>> b = 'Plus[Times[3, Global`x], Times[-2, Power[Global`y, 3]]]'
>>> from sympy.parsing.mathematica import parse_mathematica as p # in current dev version?
>>> [p(i.replace('Global`','')) for i in (a,b)]
[2*y**4 - 9, 3*x - 2*y**3]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.