在 Python 中生成給定根式的埃爾米特級數


要生成具有給定根的埃爾米特級數,請使用 Python Numpy 中的 hermite.hermfromroots() 方法。該方法返回一個 1-D 係數陣列。如果所有根都是實數,則 out 是一個實陣列,如果其中一些根是複數,則即使結果中的所有係數都是實數,out 也是複數。引數 roots 是包含根的序列。

步驟

首先,匯入必需的庫 −

import numpy as np
from numpy.polynomial import hermite as H

要生成具有給定根的埃爾米特級數,請使用 Python Numpy 中的 hermite.hermfromroots() 方法 −

print("Result...\n",H.hermfromroots((-1,0,1)))

獲取資料型別 −

print("\nType...\n",H.hermfromroots((-1,0,1)).dtype)

獲取形狀 −

print("\nShape...\n",H.hermfromroots((-1,0,1)).shape)

範例

from numpy.polynomial import hermite as H

# To generate a Hermite series with given roots, use the hermite.hermfromroots() method in Python Numpy.
# The method returns a 1-D array of coefficients. If all roots are real then out is a real array, if some of the roots are complex, then out is complex even if all the coefficients in the result are real.

# The parameter roots are the sequence containing the roots.
print("Result...\n",H.hermfromroots((-1,0,1)))

# Get the datatype
print("\nType...\n",H.hermfromroots((-1,0,1)).dtype)

# Get the shape
print("\nShape...\n",H.hermfromroots((-1,0,1)).shape)

輸出

Result...
   [0. 0.25 0. 0.125]

Type...
float64

Shape...
(4,)

更新於:2022 年 3 月 3 日

106 次瀏覽

開啟你的 職業之路

完成課程以獲得認證

開始
廣告