使用 Python 生成具有給定根的切比雪夫級數
要透過指定根生成切比雪夫級數,請在 Python Numpy 中使用 chebyshev.chebfromroots() 方法。該方法返回係數的 1-D 陣列。如果所有根都是實數,則 out 是實數陣列,如果一些根是複數,則 out 是複數,即使結果中所有的係數都是實數也是如此。引數 roots 是包含根的序列。
步驟
首先,匯入必需的庫 -
import numpy as np from numpy.polynomial import chebyshev as C
要透過指定根生成切比雪夫級數,請在 Python Numpy 中使用 chebyshev.chebfromroots() 方法 -
print("Result...\n",C.chebfromroots((-1,0,1)))
獲取資料型別 -
print("\nType...\n",C.chebfromroots((-1,0,1)).dtype)
獲取形狀 -
print("\nShape...\n",C.chebfromroots((-1,0,1)).shape)
示例
import numpy as np from numpy.polynomial import chebyshev as C # To generate a Chebyshev series with given roots, use the chebyshev.chebfromroots() method in Python Numpy. print("Result...\n",C.chebfromroots((-1,0,1))) # Get the datatype print("\nType...\n",C.chebfromroots((-1,0,1)).dtype) # Get the shape print("\nShape...\n",C.chebfromroots((-1,0,1)).shape)
輸出
Result... [ 0. -0.25 0. 0.25] Type... float64 Shape... (4,)
廣告