要从sympy表达式中获取所有变量,可以调用.free_symbols该表达式。我想检索表达式中使用的所有函数。例如,从y在
from sympy import *
f = Function('f')
g = Function('g')
x = Symbol('x')
y = f(x) + 2*g(x)
Run Code Online (Sandbox Code Playgroud)
我想得到f和g。
有什么提示吗?
对于所有函数,请使用atoms(Function).
In [40]: (f(x) + sin(x)).atoms(Function)
Out[40]: set([f(x), sin(x)])
Run Code Online (Sandbox Code Playgroud)
仅对于未定义的函数,使用atoms(AppliedUndef).
In [41]: from sympy.core.function import AppliedUndef
In [42]: (f(x) + sin(x)).atoms(AppliedUndef)
Out[42]: set([f(x)])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
319 次 |
| 最近记录: |