In this article, we’ll look at how to evaluate a 2-dimensional Hermite series using NumPy in Python at an array of points x, and y with the 3-dimensional array.
np.hermval2d method
We are using the hermite.hermval2d() function from the Numpy module to evaluate a 2D Hermite series at locations (x, y). This function returns the two-dimensional polynomial values. The x and y coordinates are the first parameters, where x and y must have the same shape, and are used to assess the two-dimensional series. And If any of them either x or y is a list or tuple, it is transformed to an array. if it isn’t an array, it is considered a scalar. The second parameter is ‘C’ which is an ordered coefficient array. here if the dimension of ‘C’ is greater than two then the remaining indices will form multiple coefficient sets. Below is the syntax of hermval2d:
Syntax: np.hermval2d(x, y, deg)
Parameters:
- x,y: array_like
- deg: List of maximum degrees
Returns: returned matrix is x.shape + (order)
Example 1:
Python3
# importing numpy and hermite modules import numpy as np from numpy.polynomial import hermite # Creating a 3D array of coefficients 'C' C = np.array([ [[ 0 , 1 , 2 ], [ 3 , 4 , 5 ]], [[ 6 , 7 , 8 ], [ 9 , 10 , 11 ]] ]) # Evaluating the 2 dimensional hermite # series ant x,y using # hermval2d() function print (hermite.hermval2d([ 1 , 2 ],[ 1 , 2 ],C)) |
Output:
[[ 54. 180.] [ 63. 205.] [ 72. 230.]]
Example 2 :
Python3
# importing numpy and hermite modules import numpy as np from numpy.polynomial import hermite # Creating a 3D array of coefficients 'C' C = np.arange( 36 ).reshape( 2 , 2 , 9 ) # Evaluating the 2 dimensional hermite # series ant x,y using # hermval2d() function x = [ 2 , 1 ] y = [ 1 , 2 ] print (hermite.hermval2d(x,y,C)) |
Output:
[[306. 288.] [321. 303.] [336. 318.] [351. 333.] [366. 348.] [381. 363.] [396. 378.] [411. 393.] [426. 408.]]