Evaluate a Hermite series at points x when coefficients are multi-dimensional in Python

To evaluate a Hermite series at points x with multi-dimensional coefficients, use the hermite.hermval() method in NumPy. This function allows you to evaluate multiple Hermite polynomials simultaneously when coefficients are stored in a multi-dimensional array.

Syntax

numpy.polynomial.hermite.hermval(x, c, tensor=True)

Parameters

The function accepts three parameters:

  • x: Points at which to evaluate the series. Can be a scalar, list, or array.
  • c: Array of coefficients where coefficients for degree n are in c[n]. For multi-dimensional arrays, additional indices represent multiple polynomials.
  • tensor: Boolean (default True). Controls how x and c are combined during evaluation.

Example with Multi-dimensional Coefficients

Let's create a 2D coefficient array and evaluate Hermite series at multiple points:

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

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

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

# Check dimensions and shape
print("\nDimensions:", c.ndim)
print("Shape:", c.shape)
print("Datatype:", c.dtype)
Coefficient Array:
[[0 1]
 [2 3]]

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

Evaluating the Hermite Series

Now evaluate the Hermite series at points x = [1, 2]:

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

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

# Evaluate Hermite series at points [1, 2]
result = H.hermval([1, 2], c)
print("Result:")
print(result)
Result:
[[ 4.  8.]
 [ 7. 13.]]

How It Works

The coefficient array represents two Hermite polynomials:

  • Column 0: Coefficients [0, 2] ? 0 + 2×H?(x)
  • Column 1: Coefficients [1, 3] ? 1 + 3×H?(x)

Since H?(x) = 2x, the polynomials become:

  • Polynomial 0: 0 + 2(2x) = 4x
  • Polynomial 1: 1 + 3(2x) = 1 + 6x

Tensor Parameter Effect

The tensor parameter controls evaluation behavior:

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

c = np.arange(4).reshape(2, 2)

# With tensor=True (default)
result_tensor = H.hermval([1, 2], c, tensor=True)
print("With tensor=True:")
print(result_tensor)

# With tensor=False
result_no_tensor = H.hermval([1, 2], c, tensor=False)
print("\nWith tensor=False:")
print(result_no_tensor)
With tensor=True:
[[ 4.  8.]
 [ 7. 13.]]

With tensor=False:
[ 4. 13.]

Conclusion

The hermite.hermval() method efficiently evaluates multiple Hermite series when coefficients are multi-dimensional. Use tensor=True to evaluate each polynomial at all x points, or tensor=False to pair x values with coefficient columns.

Updated on: 2026-03-26T19:52:49+05:30

188 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements