在Python中对点的元组进行Hermite_e级数评估
要在点x上评估Hermite_e级数,在Python的Numpy中使用hermite.hermeval()方法。 第一个参数x,如果x是一个列表或元组,它会被转换为ndarray,否则保持不变,并且视为标量。无论哪种情况,x或其元素都必须支持与自身和c的元素相加和相乘。
第二个参数C,一个按顺序排列的系数数组,使得n次项的系数包含在c[n]中。如果c是多维的,剩余的索引将枚举多个多项式。在二维情况下,可以认为系数存储在c的列中。
第三个参数tensor,如果为True,则系数数组的形状在右边用1进行扩展,每个维度对应一个。对于此操作,标量的维度为0。结果是对c中的每个系数的每个元素都进行评估。如果为False,则x会在评估中在c的列上进行广播。当c是多维时,此关键字很有用。默认值为True。
步骤
首先,导入所需的库 –
import numpy as np
from numpy.polynomial import hermite_e as H
创建一个系数数组 −
c = np.array([1, 2, 3])
显示数组 –
print("Our Array...\n",c)
检查尺寸 –
print("\nDimensions of our Array...\n",c.ndim)
获取数据类型 –
print("\nDatatype of our Array object...\n",c.dtype)
获得形状 –
print("\nShape of our Array object...\n",c.shape)
在这里,x是一个元组-
x = (5, 10, 15)
要在点x处评估一个Hermite_e系列,请使用Python Numpy中的hermite.hermeval()方法。
print("\nResult...\n",H.hermeval(x,c))
示例
import numpy as np
from numpy.polynomial import hermite_e as H
# Create an array of coefficients
c = np.array([1, 2, 3])
# Display the array
print("Our Array...\n",c)
# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)
# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)
# Get the Shape
print("\nShape of our Array object...\n",c.shape)
# Here, x is a tuple
x = (5, 10, 15)
# To evaluate a Hermite_e series at points x, use the hermite.hermeval() method in Python Numpy
print("\nResult...\n",H.hermeval(x,c))
输出
Our Array...
[1 2 3]
Dimensions of our Array...
1
Datatype of our Array object...
int64
Shape of our Array object...
(3,)
Result...
[ 83. 318. 703.]