Evaluate a 2-D Hermite series at points (x,y) with 3D array of coefficient in Python

To evaluate a 2D Hermite series at points (x, y), use the hermite.hermval2d() method in NumPy. This method returns the values of the two-dimensional polynomial at points formed with pairs of corresponding values from x and y.

The first parameter consists of x and y coordinates. The two-dimensional series is evaluated at the points (x, y), where x and y must have the same shape. 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.

The second parameter, c, is an array of coefficients ordered so that the coefficient of the term of multi-degree i,j is contained in c[i,j]. If c has dimension greater than two, the remaining indices enumerate multiple sets of coefficients.

Syntax

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

Creating the Coefficient Array

First, import the required library and create a 3D array of coefficients ?

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

# Create a 3D array of coefficients
c = np.arange(24).reshape(2, 2, 6)
print("Coefficient Array:")
print(c)
print("\nShape:", c.shape)
print("Dimensions:", c.ndim)
Coefficient 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]]]

Shape: (2, 2, 6)
Dimensions: 3

Evaluating the 2D Hermite Series

Now evaluate the 2D Hermite series at specific points (x, y) ?

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

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

# Evaluate at points (1,1) and (2,2)
result = H.hermval2d([1, 2], [1, 2], c)
print("Result of hermval2d([1, 2], [1, 2], c):")
print(result)
Result of hermval2d([1, 2], [1, 2], c):
[[108. 360.]
 [117. 385.]
 [126. 410.]
 [135. 435.]
 [144. 460.]
 [153. 485.]]

How It Works

The 3D coefficient array has shape (2, 2, 6), meaning we have 6 different 2×2 coefficient matrices. Each 2×2 matrix defines a separate 2D Hermite polynomial. The function evaluates all 6 polynomials at the given points (1,1) and (2,2), resulting in a 6×2 output array.

Example with Different Points

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

# Create simpler 2D coefficient array
c_simple = np.array([[1, 2], [3, 4]])
print("2D Coefficient array:")
print(c_simple)

# Evaluate at multiple points
x_points = [0, 1, 2]
y_points = [0, 1, 2]
result = H.hermval2d(x_points, y_points, c_simple)
print("\nEvaluation at points (0,0), (1,1), (2,2):")
print(result)
2D Coefficient array:
[[1 2]
 [3 4]]

Evaluation at points (0,0), (1,1), (2,2):
[ 1. 10. 49.]

Conclusion

The hermite.hermval2d() method efficiently evaluates 2D Hermite series at specified coordinate pairs. With 3D coefficient arrays, it can evaluate multiple polynomial sets simultaneously, making it useful for complex mathematical computations involving Hermite polynomials.

Updated on: 2026-03-26T20:35:01+05:30

236 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements