在Python中评估Hermite系列在点x处的值
要评估Hermite系列在点x处的值,在Python Numpy中使用hermite.hermval()方法。第一个参数x,如果x是列表或元组,则会转换为ndarray,否则保持不变并作为标量处理。在任何情况下,x或其元素必须支持与自身和c的元素的加法和乘法。
第二个参数C是一个按顺序排列的系数数组,其中n次项的系数包含在c[n]中。如果c是多维的,其余的索引将列举多个多项式。在二维情况下,系数可以被认为是存储在c的列中。
第三个参数tensor,如果为True,则系数数组的形状在右侧被扩展为1,每个维度对应一个。对于此操作,标量的维度为0。结果是c中的每个系数列对x的每个元素进行求值。如果为False,则x在求值时会广播到c的列上。这个关键字在c是多维的情况下很有用。默认值为True。
步骤
首先,导入所需的库-
import numpy as np
from numpy.polynomial import hermite 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处计算Hermite系列,请使用Python Numpy中的hermite.hermval()方法。
print("\nResult...\n",H.hermval(1,c))
示例
import numpy as np
from numpy.polynomial import hermite 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)
# To evaluate a Hermite series at points x, use the hermite.hermval() method in Python Numpy
print("\nResult...\n",H.hermval(1,c))
输出
Our Array...
[1 2 3]
Dimensions of our Array...
1
Datatype of our Array object...
int64
Shape of our Array object...
(3,)
Result...
11.0