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


Python Numpy np.poly2leg()用法及代碼示例

借助np.poly2leg()方法,我們可以從給定的多項式獲得勒讓德級數係數。

用法: np.poly2leg(polynomial)
返回:Return the coefficient of Legendre series.

範例1:
在這個例子中,我們可以通過使用np.poly2leg()方法,我們可以使用該方法從多項式獲得勒讓德級數的係數。


# import numpy and poly2leg 
import numpy as np 
from numpy.polynomial.legendre import poly2leg 
  
arr = np.array([0.1, 0.2, 0.3, 0.4, 0.5]) 
# using np.poly2leg() method 
ans = poly2leg(arr) 
  
print(ans)

輸出:

[ 0.3 0.44 0.48571429 0.16 0.11428571]

範例2:

# import numpy and poly2leg 
import numpy as np 
from numpy.polynomial.legendre import poly2leg 
  
arr = np.array([-0.5, -0.4, -0.3, -0.2, -0.1, 0, 0.1, 0.2, 0.3, 0.4, 0.5]) 
# using np.poly2leg() method 
ans = poly2leg(arr) 
  
print(ans)

輸出:

[-0.52692641 -0.34424242 0.08651349 0.16149184 0.27684316 0.13948718
0.13127578 0.03905114 0.02952276 0.00421226 0.00277122]



相關用法


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