如何在sympy的表达式中替换多个符号? [英] How to substitute multiple symbols in an expression in sympy?
本文介绍了如何在sympy的表达式中替换多个符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
直接分配变量不会修改追溯使用该变量的表达式.
<预><代码>>>>从 sympy 导入符号>>>x = Symbol('x')>>>y = 符号('y')>>>f = x + y>>>x = 0>>>Fx + y 解决方案
替换多个值:
<预><代码>>>>从 sympy 导入符号>>>x, y = Symbol('x y')>>>f = x + y>>>f.subs({x:10, y: 20})>>>F30Assigning a variable directly does not modify expressions that used the variable retroactively.
>>> from sympy import Symbol
>>> x = Symbol('x')
>>> y = Symbol('y')
>>> f = x + y
>>> x = 0
>>> f
x + y
解决方案
To substitute several values:
>>> from sympy import Symbol
>>> x, y = Symbol('x y')
>>> f = x + y
>>> f.subs({x:10, y: 20})
>>> f
30
这篇关于如何在sympy的表达式中替换多个符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文