Evaluate a 2-D Hermite series on the Cartesian product of x and y in Python

To evaluate a 2-D Hermite series on the Cartesian product of x and y, use the hermite.hermgrid2d() method in Python. This method evaluates a two-dimensional Hermite polynomial at points formed by the Cartesian product of input arrays.

Syntax

numpy.polynomial.hermite.hermgrid2d(x, y, c)

Parameters

The method accepts the following parameters:

  • x, y ? Input arrays. 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 converted to an ndarray first
  • c ? Array of coefficients ordered so that coefficients for terms of degree i,j are contained in c[i,j]. If c has more than two dimensions, the remaining indices enumerate multiple sets of coefficients

Example

Let's create a 2D coefficient array and evaluate the Hermite series ?

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

# Create a 2D array of coefficients
c = np.arange(4).reshape(2,2)

# Display the coefficient array
print("Coefficient Array:")
print(c)

# Check array properties
print(f"\nDimensions: {c.ndim}")
print(f"Datatype: {c.dtype}")
print(f"Shape: {c.shape}")

# Evaluate 2-D Hermite series on Cartesian product
result = H.hermgrid2d([1,2], [1,2], c)
print(f"\nResult:\n{result}")
Coefficient Array:
[[0 1]
 [2 3]]

Dimensions: 2
Datatype: int64
Shape: (2, 2)

Result:
[[18. 32.]
 [34. 60.]]

How It Works

The function evaluates the 2D Hermite polynomial defined by coefficient array c at each point (x[i], y[j]) in the Cartesian product. For coefficient matrix [[0,1], [2,3]], the polynomial is:

P(x,y) = 0*H?(x)*H?(y) + 1*H?(x)*H?(y) + 2*H?(x)*H?(y) + 3*H?(x)*H?(y)

Where H?(x) = 1 and H?(x) = 2x for Hermite polynomials.

Different Input Arrays

You can use different x and y arrays for evaluation ?

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

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

# Different x and y arrays
x_vals = [0, 1, 2]
y_vals = [0, 1]

result = H.hermgrid2d(x_vals, y_vals, c)
print("Coefficient array:")
print(c)
print(f"\nX values: {x_vals}")
print(f"Y values: {y_vals}")
print(f"\nResult shape: {result.shape}")
print("Result:")
print(result)
Coefficient array:
[[1 0]
 [0 2]]

X values: [0, 1, 2]
Y values: [0, 1]

Result shape: (3, 2)
Result:
[[ 1.  4.]
 [ 1.  8.]
 [ 1. 20.]]

Conclusion

The hermgrid2d() function efficiently evaluates 2D Hermite series on Cartesian products. It's useful for polynomial interpolation and approximation in two dimensions with Hermite basis functions.

Updated on: 2026-03-26T19:59:58+05:30

183 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements