在Python中使用NumPy对x、y和z的笛卡尔积进行3-D赫米特级数评估

在Python中使用NumPy对x、y和z的笛卡尔积进行3-D赫米特级数评估

在这篇文章中,我们将讨论如何在Python和NumPy中对x、y和z的笛卡尔乘积进行三维赫米特级数评估。

NumPy.polynomial.hermite.hermgrid3d 方法

Hermite多项式在近似理论中意义重大,因为Hermite节点被用作优化多项式插值的匹配点。为了进行Hermite微分,NumPy提供了一个名为hermite.hermgrid3d的函数,可以用来评估三维Hermite系列的笛卡尔积。这个函数只有在参数x、y和z是图元或列表的情况下才将其转换为数组,否则就不做任何改变,如果不是数组,则被视为标量。

语法 : polynomial.hermite.hermgrid3d(x, y, z, c)

参数 :

  • x,y,z: array_like
  • c:系数数组

返回:在点上的二维多项式是x和y的笛卡尔乘积。

示例 1:

在第一个例子中,让我们考虑一个大小为32的4D数组c。让我们考虑一个三维数列[1,2],[1,2],[1,2]来对4D数组进行评估。如图所示,导入必要的包,并传递适当的参数,如下所示。

import numpy as np
from numpy.polynomial import hermite
  
# co.efficient array
c = np.arange(32).reshape(2, 2, 4, 2)
  
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 4d co.eff array with a 3d hermite series
res = hermite.hermgrid3d([1, 2], [1, 2], [1, 2], 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 27]
   [28 29]
   [30 31]]]]
The shape of the array is (2, 2, 4, 2)
The dimension of the array is 4D
The datatype of the array is int64
Resultant series ---> [[[[3.6000e+01 1.1232e+04]
   [7.6000e+01 1.9664e+04]]

  [[9.2000e+01 2.0608e+04]
   [1.8000e+02 3.5920e+04]]]


 [[[4.5000e+01 1.1763e+04]
   [9.1000e+01 2.0549e+04]]

  [[1.0700e+02 2.1493e+04]
   [2.0500e+02 3.7395e+04]]]]

示例 2:

在这个例子中,我们用一个一维数组来评估笛卡尔乘积数的三维Hermite数列。

# import packages
import numpy as np
from numpy.polynomial import hermite
  
# array of coefficients
c = np.array([2,2,3])
print(c)
  
# shape of the array is
print("Shape of the array is : ",c.shape)
  
# dimension of the array
print("The dimension of the array is : ",c.ndim)
  
# Datatype of the array
print("Datatype of our Array is : ",c.dtype)
  
#evaluating hermite series
print(hermite.hermgrid3d([1,2],[3,4],[5,6],c))

输出:

[2 2 3]
Shape of the array is :  (3,)
The dimension of the array is :  1
Datatype of our Array is :  int64
[4604. 5460.]

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Numpy 多项式