Evaluate a 2-D Hermite_e series on the Cartesian product of x and y 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.

Syntax

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

Parameters

The method accepts the following parameters ?

  • x, y ? The two-dimensional series is evaluated at the 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, otherwise it is left unchanged and, if it isn't an ndarray, it is treated as a scalar.
  • c ? An array of coefficients ordered so that the 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.

How It Works

The Hermite_e polynomial series is defined as the sum of terms where each term is a product of Hermite_e polynomials in x and y directions. The coefficient array c determines the contribution of each term.

If c has fewer than two dimensions, ones are implicitly appended to its shape to make it 2-D. The shape of the result will be c.shape[2:] + x.shape.

Example

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

import numpy as np
from numpy.polynomial import hermite_e 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("\nDimensions:", c.ndim)
print("Datatype:", c.dtype)
print("Shape:", c.shape)

# Evaluate the 2-D Hermite_e series
result = H.hermegrid2d([1, 2], [1, 2], c)
print("\nResult:")
print(result)
Coefficient Array:
[[0 1]
 [2 3]]

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

Result:
[[ 6. 10.]
 [11. 18.]]

Different Input Arrays

Let's see how it works with different x and y values ?

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

# Create coefficient array
c = np.array([[1, 2], [3, 4]])

# Evaluate with different points
x_points = [0, 1, 2]
y_points = [0, 1]

result = H.hermegrid2d(x_points, y_points, c)
print("Coefficient array:")
print(c)
print("\nX points:", x_points)
print("Y points:", y_points)
print("\nResult shape:", result.shape)
print("Result:")
print(result)
Coefficient array:
[[1 2]
 [3 4]]

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

Result shape: (2, 3)
Result:
[[ 1.  4. 13.]
 [ 3. 10. 31.]]

Key Points

  • The function evaluates a 2D Hermite_e polynomial series at Cartesian product points
  • Input x and y can be scalars, lists, tuples, or arrays
  • The coefficient array c must be at least 2-dimensional
  • The result shape depends on both the coefficient array and input point arrays

Conclusion

The hermegrid2d() method provides an efficient way to evaluate 2D Hermite_e polynomial series on a grid of points. It's particularly useful for mathematical computations involving orthogonal polynomials in two dimensions.

Updated on: 2026-03-26T21:11:54+05:30

206 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements