Friday, December 27, 2024
Google search engine
HomeLanguagesEvaluate 2-D Hermite series on the Cartesian product of x and y...

Evaluate 2-D Hermite series on the Cartesian product of x and y with 3d array of coefficient using NumPy in Python

In this article, we will discuss how to Evaluate a 2-D Hermite series on the Cartesian product of x and y with a 3d array of coefficients in Python and NumPy.

NumPy.polynomial.hermite.hermgrid2d method

Hermite polynomials are significant in approximation theory because the Hermite nodes are used as matching points for optimizing polynomial interpolation. 
To perform Hermite differentiation, NumPy provides a function called Hermite.hermgrid2d which can be used to evaluate the cartesian product of the 3D Hermite series. This function converts the parameters x and y to array only if they are tuples or a list, otherwise, it is left unchanged and, if it is not an array, it is treated as a scalar.

Syntax: polynomial.hermite.hermgrid2d(x, y, c)

Parameters:

  • x,y: array_like
  • c: array of coefficients

Return: The values of the two dimensional polynomial at points in the Cartesian product of x and y.

Example 1:

In the first example. let us consider a 3D array c that has 24 elements.  Let us consider a 2D series [2,1],[2,1] to evaluate against the 1D array. Import the necessary packages as shown and pass the appropriate parameters as shown below.

Python3




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}')


Output:

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.]]]

Example 2:

In the first example. let us consider a 3D array c that has 48 elements.  Let us consider a 2D series [1,2],[1,2] to evaluate against the 1D array. Import the necessary packages as shown and pass the appropriate parameters as shown below.

Python3




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}')


Output:

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.]]]

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments