使用Python在多维数组点x上评估Hermite级数
要在点x上评估Hermite级数,请使用Python Numpy中的hermite.hermval()方法。第一个参数x,如果x是一个列表或元组,则会转换为ndarray,否则保持不变并视为标量。在任一情况下,x或其元素必须支持与自己和c的元素的加法和乘法。
第二个参数C是一个按顺序排列的系数数组,使得n次项的系数包含在c[n]中。如果c是多维的,剩余的索引会枚举多项式。在二维情况下,可以将系数视为存储在c的列中。
第三个参数tensor,如果为True,则将系数数组的形状扩展,右侧为每个x维度的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...
",c)
检查尺寸 –
print("
Dimensions of our Array...
",c.ndim)
获取数据类型−
print("
Datatype of our Array object...
",c.dtype)
获取形状 –
print("
Shape of our Array object...
",c.shape)
这里,x是一个二维数组 –
x = np.array([[1,2],[3,4]])
使用Python Numpy中的hermite.hermval()方法在点x上评估Hermite系列。
print("
Result...
",H.hermval(x,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...
",c)
# Check the Dimensions
print("
Dimensions of our Array...
",c.ndim)
# Get the Datatype
print("
Datatype of our Array object...
",c.dtype)
# Get the Shape
print("
Shape of our Array object...
",c.shape)
# Here, x is a 2D array
x = np.array([[1,2],[3,4]])
# To evaluate a Hermite series at points x, use the hermite.hermval() method in Python Numpy
print("
Result...
",H.hermval(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...
[[ 11. 51.]
[115. 203.]]