在Python中使用NumPy在点x的列表中评估赫米特级数
在这篇文章中,我们将着眼于在Python和NumPy中对一个点x的列表进行Hermite数列的评估方法。
示例:
List : [6,7,8,9,10]
Result : [102175. 191631. 329175. 529399. 808815.]
解释 : 在点x处的Hermite数列。
NumPy.polynomial.hermite.hermval() 方法
为了评估一个在x处的点列表的Hermite数列,用户需要调用Python中Numpy库的hermite.hermval()方法。此外,用户需要向该函数传递第一个参数,即x,其中x是一个列表或元组,第二个参数是C,是一个系数数组。
语法 : np.polynomial.hermite.hermval(x, c)
参数 :
- x: 列表或元组
- c: 系数阵列
返回:返回乘法后的系列系数。
示例 1:
在这个例子中,我们创建了一个一维的5个数据点的数组,并进一步创建了一个名为x的列表,之后我们使用hermite.hermval()方法,并传递所需的参数,在一个点的列表[6,7,8,9,10]评估Hermite数列。
import numpy as np
from numpy.polynomial import hermite
a = np.array([1,2,3,4,5])
# Dimensions of Array
print("Dimensions of Array: ",a.ndim)
# Shape of the array
print("\nShape of Array: ",a.shape)
# List
x = [6,7,8,9,10]
# To evaluate a Hermite series at points x
print("\nHermite series at point", hermite.hermval(x,a))
输出 :
Dimensions of Array: 1
Shape of Array: (5,)
Hermite series at point [102175. 191631. 329175. 529399. 808815.]
示例 2:
在这个例子中,我们创建了一个由10个数据点组成的二维数组,并进一步创建了一个名为x的列表,之后我们使用hermite.hermval()方法并传递所需参数,在列表中的点[11,12,13,14,15]处评估赫米特数列。
import numpy as np
from numpy.polynomial import hermite
a = np.array([[1,2,3,4,5],[6,7,8,9,10]])
# Dimensions of Array
print("Dimensions of Array: ",a.ndim)
# Shape of the array
print("\nShape of Array: ",a.shape)
# List
x = [11,12,13,14,15]
# To evaluate a Hermite series at points x
print("\nHermite series at point", hermite.hermval(x,a))
输出:
Dimensions of Array: 2
Shape of Array: (2, 5)
Hermite series at point [[133. 145. 157. 169. 181.]
[156. 170. 184. 198. 212.]
[179. 195. 211. 227. 243.]
[202. 220. 238. 256. 274.]
[225. 245. 265. 285. 305.]]