Non-sequential substitution in SymPy

后端 未结 5 889
醉梦人生
醉梦人生 2021-02-13 14:11

I\'m trying to use [SymPy][1] to substitute multiple terms in an expression at the same time. I tried the [subs function][2] with a dictionary as parameter, but found out that i

5条回答
  •  太阳男子
    2021-02-13 14:49

    Example for @~unutbu's answer:

    >>> import ordereddict # collections.OrderedDict in Python 2.7+
    >>> from sympy import *
    >>> x,y,z = symbols('xyz')
    >>> x.subs(ordereddict.OrderedDict([(x,y),(y,z)]))
    y
    >>> x.subs(ordereddict.OrderedDict([(y,z),(x,y)]))
    z
    

提交回复
热议问题