Evaluate a Hermite_e series at points x broadcast over the columns of the coefficient in Python

To evaluate a Hermite_e series at points x broadcast over the columns of coefficients, use the hermite_e.hermeval() method in NumPy. This function allows you to evaluate multiple polynomials simultaneously with different broadcasting behaviors.

Syntax

numpy.polynomial.hermite_e.hermeval(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 multidimensional arrays, columns represent different polynomials.
  • tensor ? Boolean flag controlling broadcasting behavior. When False, x is broadcast over columns of c.

Example with tensor=False

When tensor=False, each element of x is evaluated against the corresponding column of coefficients ?

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

# Create a multidimensional array of coefficients
c = np.arange(4).reshape(2, 2)
print("Coefficient array:")
print(c)
print("\nShape of coefficient array:", c.shape)

# Evaluate Hermite_e series with tensor=False
points = [1, 2]
result = H.hermeval(points, c, tensor=False)
print("\nEvaluating at points", points, "with tensor=False:")
print("Result:", result)
Coefficient array:
[[0 1]
 [2 3]]

Shape of coefficient array: (2, 2)

Evaluating at points [1, 2] with tensor=False:
Result: [2. 7.]

Example with tensor=True

When tensor=True (default), every column is evaluated for every element of x ?

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

# Same coefficient array
c = np.arange(4).reshape(2, 2)
points = [1, 2]

# Evaluate with tensor=True (default)
result_tensor = H.hermeval(points, c, tensor=True)
print("Evaluating with tensor=True:")
print("Result shape:", result_tensor.shape)
print("Result:")
print(result_tensor)
Evaluating with tensor=True:
Result shape: (2, 2)
Result:
[[2. 3.]
 [8. 9.]]

Understanding Broadcasting Behavior

The difference between tensor=True and tensor=False affects how evaluation points and coefficient columns interact:

Parameter Broadcasting Result Shape
tensor=False x[i] evaluated with c[:, i] 1D array
tensor=True Every x[i] with every c[:, j] 2D array

Conclusion

Use tensor=False to evaluate corresponding points with coefficient columns. Use tensor=True for full cross-evaluation of all points against all polynomial columns.

Updated on: 2026-03-26T21:01:36+05:30

217 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements