在Python中评估多维数组点x处的Hermite级数
要评估点x处的Hermite级数,请在Python Numpy中使用hermite.hermval()方法。第一个参数x,如果x是列表或元组,则将其转换为ndarray,否则将其保持不变并将其视为标量。无论哪种情况,x或其元素都必须支持自身以及c的元素之间的加法和乘法。
第二个参数C,一个系数数组,这些系数的顺序使得n次幂的系数包含在c[n]中。如果c是多维的,则其余索引枚举多个多项式。在二维情况下,可以认为系数存储在c的列中。
第三个参数tensor,如果为True,则系数数组的形状在右侧用1扩展,每个x的维度一个。标量对此操作的维度为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]])
要评估点x处的Hermite级数,请在Python Numpy中使用hermite.hermval()方法:
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.]]
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP