在 Python 中生成具有給定復根的勒讓德級數
如果要生成勒讓德級數,請在 Python 中使用 polynomial.legendre.legfromroots() 方法。該方法返回係數的 1 維陣列。如果所有根都是實數,則 out 是一個實數陣列;如果有些根是複數,則 out 是複數,即使結果中的所有係數都是實數。引數 roots 是包含根的序列。
步驟
首先,匯入所需的庫 −
from numpy.polynomial import legendre as L
在 Python 中使用 polynomial.legendre.legfromroots() 方法生成勒讓德級數 −
j = complex(0,1)
print("Result...\n",L.legfromroots((-j, j)))獲取資料型別 −
print("\nType...\n",L.legfromroots((-j, j)).dtype)獲取形狀 −
print("\nShape...\n",L.legfromroots((-j, j)).shape)示例
from numpy.polynomial import legendre as L
# To generate a Legendre series, use the polynomial.legendre.legfromroots() method in Python
j = complex(0,1)
print("Result...\n",L.legfromroots((-j, j)))
# Get the datatype
print("\nType...\n",L.legfromroots((-j, j)).dtype)
# Get the shape
print("\nShape...\n",L.legfromroots((-j, j)).shape)輸出
Result... [1.33333333+0.j 0. +0.j 0.66666667+0.j] Type... complex128 Shape... (3,)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP