使用Python生成具有给定根的Hermite级数
要生成具有给定根的Hermite级数,请使用Python中的hermite.hermfromroots()方法。该方法返回一个1-D系数数组。如果所有根都是实数,则输出是一个实数组;如果某些根是复数,则输出即使所有结果中的系数都是实数,输出也是复数。参数roots是包含根的序列。
步骤
首先,导入所需的库-
import numpy as np
from numpy.polynomial import hermite as H
使用Python的Numpy库中的hermite.hermfromroots()方法生成具有给定根的Hermite系列。
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,)