Evaluate a 2-D Hermite_e series on the Cartesian product of x and y with 1d 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 evaluates a two-dimensional Hermite_e polynomial at points formed by the Cartesian product of two arrays.

Syntax

numpy.polynomial.hermite_e.hermegrid2d(x, y, c)

Parameters

  • x, y − Arrays representing the coordinates. The series is evaluated at points in the Cartesian product of x and y
  • c − Array of coefficients ordered so that coefficients for terms of degree i,j are in c[i,j]

Basic Example

Let's start with a simple example using a 1D coefficient array ?

import numpy as np
from numpy.polynomial import hermite_e as H

# Create a 1d array of coefficients
c = np.array([3, 5])

# Display the coefficient array
print("Coefficients:", c)
print("Shape:", c.shape)

# Evaluate on Cartesian product
x_points = [1, 2]
y_points = [1, 2] 
result = H.hermegrid2d(x_points, y_points, c)
print("\nResult:", result)
Coefficients: [3 5]
Shape: (2,)

Result: [21. 34.]

Using 2D Coefficient Array

For a true 2D Hermite_e series, we need a 2D coefficient array ?

import numpy as np
from numpy.polynomial import hermite_e as H

# Create a 2D coefficient array
c = np.array([[1, 2], [3, 4]])
print("2D Coefficients:\n", c)

# Define coordinate arrays
x = [0, 1]
y = [0, 1]

# Evaluate the 2D Hermite_e series
result = H.hermegrid2d(x, y, c)
print("\nCartesian product evaluation:")
print("x =", x)
print("y =", y) 
print("Result shape:", result.shape)
print("Result:\n", result)
2D Coefficients:
 [[1 2]
 [3 4]]

Cartesian product evaluation:
x = [0, 1]
y = [0, 1]
Result shape: (2, 2)
Result:
 [[ 1.  4.]
 [ 4. 10.]]

How It Works

The method evaluates the 2D Hermite_e polynomial:

  • Creates a Cartesian product of x and y coordinates
  • For coefficient array c[i,j], evaluates terms of degree i in x and degree j in y
  • Returns results with shape matching the Cartesian product

Different Array Sizes

You can use different sized coordinate arrays ?

import numpy as np
from numpy.polynomial import hermite_e as H

# 2D coefficient array
c = np.array([[1, 0], [2, 1]])

# Different sized arrays
x = [0, 1, 2]  # 3 points
y = [0, 1]     # 2 points

result = H.hermegrid2d(x, y, c)
print("x points:", len(x))
print("y points:", len(y))
print("Result shape:", result.shape)
print("Result:\n", result)
x points: 3
y points: 2
Result shape: (2, 3)
Result:
 [[1. 1. 1.]
 [1. 3. 9.]]

Comparison

Coefficient Array Polynomial Terms Use Case
1D array [a, b] a + b*x (treated as 2D) Simple polynomials
2D array [[a,b],[c,d]] a + b*y + c*x + d*x*y True 2D polynomials

Conclusion

The hermegrid2d() function efficiently evaluates 2D Hermite_e series on Cartesian coordinate grids. Use 2D coefficient arrays for genuine bivariate polynomials and leverage the Cartesian product feature for grid-based evaluations.

Updated on: 2026-03-26T19:43:45+05:30

228 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements