SymPy 标量替换不起作用?
from sympy import * x,y,s = symbols('xys') z = (1 - 2*x*x) w = (1 + 2*x*x) q = 2*x*x*2*y*y sub = {2*x*x: s} print w.subs(sub) print z.subs(sub) print q print q.subs(sub)
我得到的输出:
1 + s 1 - 2*x**2 4*x**2*y**2 4*x**2*y**2
我期望的输出:
1 + s 1 - s 4*x**2*y**2 2*y**2*s
我做错了什么吗?
from sympy import * x,y,s = symbols('xys') z = (1 - 2*x*x) w = (1 + 2*x*x) q = 2*x*x*2*y*y sub = {2*x*x: s} print w.subs(sub) print z.subs(sub) print q print q.subs(sub)
The output I get:
1 + s 1 - 2*x**2 4*x**2*y**2 4*x**2*y**2
The output I expect:
1 + s 1 - s 4*x**2*y**2 2*y**2*s
Do I do something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Sympy 似乎与它所匹配的内容不一致。例如,更改匹配替换表达式上的符号允许与 z 匹配。我会考虑将此示例添加到此问题中。我还会尝试 Sympy 邮件列表。请记住,该项目还没有达到 1.0 版本,因此它的功能还不会很完美(或者可能与任何软件一样)。
Sympy seems to be inconsistent in what it matches. For instance, changing the sign on the matching substitution expression allows z to be matched with. I would consider adding this example to this issue. I would also try the Sympy mailing list. Remember, this project isn't even to version number 1.0 yet so things aren't going to be perfect just yet with it (or probably ever as with any software).