Evaluate a 3-D Hermite series on the Cartesian product of x, y and z with 2d array of coefficient in Python

To evaluate a 3-D Hermite series on the Cartesian product of x, y and z, use the hermite.hermgrid3d(x, y, z, c) method in Python. The method returns the values of the three-dimensional polynomial at points in the Cartesian product of x, y and z.

Understanding the Parameters

The hermgrid3d() method accepts four parameters:

  • x, y, z ? The three dimensional series is evaluated at the points in the Cartesian product of x, y, and z. If x, y, or z 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. If c has fewer than three dimensions, ones are implicitly appended to its shape to make it 3-D.

The shape of the result will be c.shape[2:] + x.shape + y.shape + z.shape.

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 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 3-D Hermite series on the Cartesian product
print("\nResult...\n",H.hermgrid3d([1,2],[1,2],[1,2],c))
Our Array...
 [[0 1]
 [2 3]]

Dimensions of our Array...
2

Datatype of our Array object...
int64

Shape of our Array object...
(2, 2)

Result...
 [[ 86. 154.]
 [152. 272.]]

How It Works

The function evaluates the Hermite series using the coefficient matrix c at each point in the Cartesian product of the input arrays. Since we passed [1,2] for each coordinate, it creates a 3D grid with 8 points total (2×2×2), but the result shape depends on the coefficient array structure.

Different Input Arrays Example

Let's try with different coordinate arrays to see how the Cartesian product works ?

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

# Same coefficient array
c = np.arange(4).reshape(2,2)

# Different coordinate arrays
x_vals = [0, 1]
y_vals = [1]  
z_vals = [0, 1, 2]

result = H.hermgrid3d(x_vals, y_vals, z_vals, c)
print("Result shape:", result.shape)
print("Result values:\n", result)
Result shape: (2, 1, 3)
Result values:
 [[[2. 2. 2.]]

 [[3. 3. 3.]]]

Conclusion

The hermite.hermgrid3d() method efficiently evaluates 3-D Hermite series on Cartesian product grids. The output dimensions depend on both the coefficient array shape and the input coordinate arrays, making it versatile for multidimensional polynomial evaluations.

Updated on: 2026-03-26T20:04:46+05:30

189 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements