當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python sympy.as_terms()用法及代碼示例

借助sympy.as_terms()方法,我們可以通過使用sympy.as_terms()方法。

用法: sympy.as_terms()
返回:Return list of terms that are in mathematical expression.

範例1:
在這個例子中,我們可以通過使用sympy.as_terms()方法,我們能夠在列表中獲得數學表達式的項。


# import sympy 
from sympy import * 
  
x, y = symbols('x y') 
  
# Use sympy.as_terms() method 
gfg = (x**2 + 2 * x*y + y**2).as_terms() 
    
print(gfg)

輸出:

([(x**2, ((1.0, 0.0), (2, 0), ())), (y**2, ((1.0, 0.0), (0, 2), ())), (2*x*y, ((2.0, 0.0), (1, 1), ()))], [x, y])

範例2:

# import sympy 
from sympy import * 
  
x, y = symbols('x y') 
  
# Use sympy.as_terms() method 
gfg = (y + x).as_terms() 
    
print(gfg)

輸出:

([(x, ((1.0, 0.0), (1, 0), ())), (y, ((1.0, 0.0), (0, 1), ()))], [x, y])



相關用法


注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 Python | sympy.as_terms() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。