Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Evaluate a Hermite series at points x and the shape of coefficient array extended for each dimension of x in Python
The Hermite series evaluation in Python NumPy allows you to compute polynomial values at specific points using the hermite.hermval() method. This function is particularly useful when working with multidimensional coefficient arrays and controlling how the evaluation is broadcast across dimensions.
Syntax
hermite.hermval(x, c, tensor=True)
Parameters
The hermval() method accepts three parameters:
- x: Points at which to evaluate the series. Can be a scalar, list, or array
-
c: Coefficient array where
c[n]contains coefficients for degree n terms - tensor: Controls broadcasting behavior (default: True)
Understanding the tensor Parameter
When tensor=True, the coefficient array shape is extended with ones for each dimension of x, evaluating every coefficient column for every x element. When tensor=False, x is broadcast over the coefficient columns.
Basic Example
import numpy as np
from numpy.polynomial import hermite as H
# Create a multidimensional array of coefficients
c = np.arange(8).reshape(2,4)
# Display the array
print("Coefficient Array:")
print(c)
# Check array properties
print("\nDimensions:", c.ndim)
print("Datatype:", c.dtype)
print("Shape:", c.shape)
Coefficient Array: [[0 1 2 3] [4 5 6 7]] Dimensions: 2 Datatype: int64 Shape: (2, 4)
Evaluating with tensor=True
import numpy as np
from numpy.polynomial import hermite as H
# Coefficient array
c = np.arange(8).reshape(2,4)
# Evaluate at points [1, 2] with tensor=True
result_tensor = H.hermval([1, 2], c, tensor=True)
print("Result with tensor=True:")
print(result_tensor)
print("Shape:", result_tensor.shape)
Result with tensor=True: [[ 8. 16.] [11. 21.] [14. 26.] [17. 31.]] Shape: (4, 2)
Evaluating with tensor=False
import numpy as np
from numpy.polynomial import hermite as H
# Coefficient array
c = np.arange(8).reshape(2,4)
# Evaluate at points [1, 2] with tensor=False
result_no_tensor = H.hermval([1, 2], c, tensor=False)
print("Result with tensor=False:")
print(result_no_tensor)
print("Shape:", result_no_tensor.shape)
Result with tensor=False: [ 8. 16.] Shape: (2,)
Comparison
| Parameter | Broadcasting Behavior | Output Shape |
|---|---|---|
tensor=True |
Each coefficient column evaluated for every x element | (coeff_cols, x_elements) |
tensor=False |
x is broadcast over coefficient columns | (x_elements,) |
Conclusion
The hermite.hermval() method provides flexible Hermite series evaluation with the tensor parameter controlling how multidimensional coefficients are broadcast. Use tensor=True for comprehensive evaluation across all coefficient combinations.
