Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Evaluate a 2-D Hermite_e series on the Cartesian product of x and y with 3d array of coefficient in Python
To evaluate a 2-D Hermite_e series on the Cartesian product of x and y, use the hermite_e.hermegrid2d() method in Python. This method returns the values of the two-dimensional polynomial at points in the Cartesian product of x and y coordinates.
Syntax
numpy.polynomial.hermite_e.hermegrid2d(x, y, c)
Parameters
The parameters are:
- x, y: The two dimensional series is evaluated at points in the Cartesian product of x and y. If x or y is a list or tuple, it is first converted to an ndarray
- c: Array of coefficients ordered so that coefficients for terms of degree i,j are contained in c[i,j]. If c has dimension greater than two, the remaining indices enumerate multiple sets of coefficients
Example
Let's create a 3D array of coefficients and evaluate the Hermite_e series ?
import numpy as np
from numpy.polynomial import hermite_e as H
# Create a 3d array of coefficients
c = np.arange(24).reshape(2, 2, 6)
# Display the array
print("Our Array...\n", c)
# Check the dimensions
print("\nDimensions of our Array...\n", c.ndim)
# Get the datatype
print("\nDatatype of our Array object...\n", c.dtype)
# Get the shape
print("\nShape of our Array object...\n", c.shape)
# Evaluate 2-D Hermite_e series on Cartesian product
print("\nResult...\n", H.hermegrid2d([1, 2], [1, 2], c))
Our Array... [[[ 0 1 2 3 4 5] [ 6 7 8 9 10 11]] [[12 13 14 15 16 17] [18 19 20 21 22 23]]] Dimensions of our Array... 3 Datatype of our Array object... int64 Shape of our Array object... (2, 2, 6) Result... [[[ 36. 60.] [ 66. 108.]] [[ 40. 66.] [ 72. 117.]] [[ 44. 72.] [ 78. 126.]] [[ 48. 78.] [ 84. 135.]] [[ 52. 84.] [ 90. 144.]] [[ 56. 90.] [ 96. 153.]]]
How It Works
The method evaluates the 2-D Hermite_e polynomial series at each point (x_i, y_j) where x_i comes from the first array [1, 2] and y_j comes from the second array [1, 2]. The 3D coefficient array has shape (2, 2, 6), so it contains 6 different coefficient matrices of size 2×2. The result has shape (6, 2, 2) corresponding to the 6 coefficient sets evaluated at the 2×2 Cartesian product points.
Conclusion
The hermegrid2d() method efficiently evaluates 2-D Hermite_e series on Cartesian products. It handles multiple coefficient sets when the coefficient array has more than 2 dimensions, making it useful for batch polynomial evaluations.
