简体   繁体   中英

f(x).subs() substitution in sympy (python)

I defined symbols a and f. I'm expecting to use "a(3).subs(a,f)" to get f(3), but instead I got a(3). What's wrong with it?

a, f = symbols('a f')

a(3).subs(a,f)

您已将f定义为一个函数,然后将其替换为symbols()的返回值。

You can use replace to change the function. Here are some examples.

import sympy as sp

f = sp.Function('f')
g = sp.Function('g')
x,y = sp.symbols('x, y')

f(x).replace(f, g)

g(x)

f(x).replace(f, sp.sin)

sin(x)

f(x,y).replace(f, lambda *args: sp.exp(-5 * args[0] + args[1] ))

exp(-5*x + y)

The documentation provides an extensive list of additional examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM