在Python中使用NumPy对x和y的笛卡尔乘积的二维赫米特级数进行评估,并使用三维系数阵列
在这篇文章中,我们将讨论如何在Python和NumPy中评估一个具有三维系数数组的x和y的笛卡尔积的二维Hermite数列。
NumPy.polynomial.hermite.hermgrid2d 方法
Hermite多项式在近似理论中意义重大,因为Hermite节点被用作优化多项式插值的匹配点。
为了进行Hermite微分,NumPy提供了一个名为Hermite.hermgrid2d的函数,可以用来评估三维Hermite数列的笛卡尔积。这个函数只有在参数x和y是图元或列表的情况下才将其转换为数组,否则就不做任何改变,如果不是数组,则被视为标量。
语法 : polynomial.hermite.hermgrid2d(x, y, c)
参数 :
- x,y: array_like
- c:系数数组
返回:二维多项式在x和y的笛卡尔乘积中各点的值。
示例 1:
在第一个例子中,让我们考虑一个有24个元素的三维数组c。让我们考虑一个二维数列[2,1],[2,1]来对一维数组进行评估。如图所示,导入必要的包,并传递适当的参数,如下所示。
import numpy as np
from numpy.polynomial import hermite
# coefficient array
c = np.arange(24).reshape(2,2,6)
print(f'The coefficient 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 3d coeff array with a 2d
# hermite series
res = hermite.hermgrid2d([2,1], [2,1], c)
# resultant array
print(f'Resultant series ---> {res}')
输出:
The coefficient 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]]]
The shape of the array is (2, 2, 6)
The dimension of the array is 3D
The datatype of the array is int64
Resultant series ---> [[[360. 204.]
[192. 108.]]
[[385. 219.]
[207. 117.]]
[[410. 234.]
[222. 126.]]
[[435. 249.]
[237. 135.]]
[[460. 264.]
[252. 144.]]
[[485. 279.]
[267. 153.]]]
示例 2:
在第一个例子中,让我们考虑一个有48个元素的三维数组c。让我们考虑一个二维数列[1,2],[1,2]来对一维数组进行评估。如图所示,导入必要的包,并传递适当的参数,如下所示。
import numpy as np
from numpy.polynomial import hermite
# coefficient array
c = np.arange(48).reshape(2,2,12)
print(f'The coefficient 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 3d coeff array with a 2d
# hermite series
res = hermite.hermgrid2d([1,2], [1,2], c)
# resultant array
print(f'Resultant series ---> {res}')
输出:
The coefficient 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 27 28 29 30 31 32 33 34 35]
[36 37 38 39 40 41 42 43 44 45 46 47]]]
The shape of the array is (2, 2, 12)
The dimension of the array is 3D
The datatype of the array is int64
Resultant series ---> [[[216. 384.]
[408. 720.]]
[[225. 399.]
[423. 745.]]
[[234. 414.]
[438. 770.]]
[[243. 429.]
[453. 795.]]
[[252. 444.]
[468. 820.]]
[[261. 459.]
[483. 845.]]
[[270. 474.]
[498. 870.]]
[[279. 489.]
[513. 895.]]
[[288. 504.]
[528. 920.]]
[[297. 519.]
[543. 945.]]
[[306. 534.]
[558. 970.]]
[[315. 549.]
[573. 995.]]]