在Python中用多维系数数组对x点的赫米特级数进行评估
在这篇文章中,我们将讨论如何在Python和NumPy中用一个多维系数数组在x点评估Hermite数列。
示例:
Input: [[11 12][13 14]]
Output: [[37. 63.][40. 68.]]
解释:Hermite数列在点x。
NumPy.polynomial.hermite.hermval 方法
为了在x点评估一个多维系数数组的Hermite数列,NumPy提供了一个名为hermite.hermval()的函数。它需要两个参数x和c。而x是一个元组或列表。它被认为是一个标量。但是,参数x应该支持在其内部以及与c的元素的乘法和加法。如果c是一个一维数组,那么它的形状将与x相同。如果c是多维的,那么结果的形状取决于张量的值。
语法: polynomial.hermite.hermval(x,c, tensor)
参数:
- x: array_like
- c:系数的数组
- tensor: boolean(optional).
返回:在x点的赫米特数列。
示例 1:
在第一个例子中,让我们考虑一个二维数组,并在x点评估一个Hermite级数,导入必要的包并传递适当的参数,如图所示
import numpy as np
from numpy.polynomial import hermite
# co.eff array
c = np.array([[11, 12], [13, 14]])
print(f'The co.efficient array is {c}')
print(f'The shape of the array is {c.shape}')
print(f'The dimension of the array is {c.ndim}D')
print(f'The datatype of the array is {c.dtype}')
# evaluating multidimensional array of hermiteseries
res = hermite.hermval([1, 2], c)
# resultant array
print(f'Resultant series ---> {res}')
输出:
The co.efficient array is
[[11 12]
[13 14]]
The shape of the array is (2, 2)
The dimension of the array is 2D
The datatype of the array is int32
Resultant series --->
[[37. 63.]
[40. 68.]]
示例 2:
在第二个例子中,让我们考虑一个三维数组,并在x点评估一个Hermite数列。导入必要的包并传递适当的参数,如图所示
import numpy as np
from numpy.polynomial import hermite
# co.eff array
c = np.arange(27).reshape(3, 3, 3)
print(f'The co.efficient array is {c}')
print(f'The shape of the array is {c.shape}')
print(f'The dimension of the array is {c.ndim}D')
print(f'The datatype of the array is {c.dtype}')
# evaluating multidimensional array of hermiteseries
res = hermite.hermval([17, 22], c)
# resultant array
print(f'Resultant series ---> {res}')
输出:
The co.efficient array is
[[[ 0 1 2]
[ 3 4 5]
[ 6 7 8]]
[[ 9 10 11]
[12 13 14]
[15 16 17]]
[[18 19 20]
[21 22 23]
[24 25 26]]]
The shape of the array is (3, 3, 3)
The dimension of the array is 3D
The datatype of the array is int32
Resultant series --->
[[[21078. 35208.]
[22267. 37187.]
[23456. 39166.]]
[[24645. 41145.]
[25834. 43124.]
[27023. 45103.]]
[[28212. 47082.]
[29401. 49061.]
[30590. 51040.]]]