簡體   English   中英

Sympy:從表達式中獲取函數

[英]Sympy: Get functions from expression

要從sympy表達式中獲取所有變量,可以在表達式上調用.free_symbols 我想檢索表達式中使用的所有函數 例如,從y in

from sympy import *

f = Function('f')
g = Function('g')

x = Symbol('x')

y = f(x) + 2*g(x)

我想得到fg

任何提示?

atoms可以解決問題:

for f in y.atoms(Function):
    print(f.func)

對於所有函數,使用atoms(Function)

In [40]: (f(x) + sin(x)).atoms(Function)
Out[40]: set([f(x), sin(x)])

對於僅未定義的函數,請使用atoms(AppliedUndef)

In [41]: from sympy.core.function import AppliedUndef

In [42]: (f(x) + sin(x)).atoms(AppliedUndef)
Out[42]: set([f(x)])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM