Open In App

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

Last Updated : 03 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will discuss how to Evaluate a 2-D Hermite series on the Cartesian product of x and y with a 1d array of coefficients in Python using 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 the Hermite cartesian product, NumPy provides a function called Hermite.hermgrid2d which can be used to evaluate the cartesian product of the 1D 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

Returns: Two dimensional polynomials at points as cartesian products of x and y.

Example 1:

In the first example. let us consider a 1D array c that has 5 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.array([1, 2, 3, 4, 5])
  
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 1d co.eff array with a 2d
# hermite series
res = hermite.hermgrid2d([1, 2], [1, 2], c)
  
# resultant array
print(f'Resultant series ---> {res}')


Output:

The co.efficient array is [1 2 3 4 5]
The shape of the array is (5,)
The dimension of the array is 1D
The datatype of the array is int64
Resultant series ---> [1077. 2259.]

Example 2:

In the first example. let us consider a 1D array c that has 10 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.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
  
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 1d coeff array with a 2d
# hermite series
res = hermite.hermgrid2d([2, 1], [2, 1], c)
  
# resultant array
print(f'Resultant series ---> {res}')


Output:

The co.efficient array is [ 1  2  3  4  5  6  7  8  9 10]
The shape of the array is (10,)
The dimension of the array is 1D
The datatype of the array is int64
Resultant series ---> [-45325. 189045.]


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads