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_e series at points x and the shape of the coefficient array extended for each dimension of x in Python
To evaluate a Hermite_e series at points x, use the hermite_e.hermeval() method in Python NumPy. This function allows you to evaluate Hermite_e polynomials at specific points and control how the coefficient array is handled for different dimensions.
Parameters
The hermeval() method accepts three key parameters:
- x: The evaluation points. If x is a list or tuple, it is converted to an ndarray. The elements must support addition and multiplication operations.
- c: Array of coefficients where coefficients for terms of degree n are in c[n]. For multidimensional arrays, remaining indices enumerate multiple polynomials.
- tensor: Boolean parameter controlling shape extension. If True (default), the coefficient array shape is extended for each dimension of x. If False, x is broadcast over the columns of c.
Example with Tensor=True
Let's create a multidimensional coefficient array and evaluate the Hermite_e series ?
import numpy as np
from numpy.polynomial import hermite_e as H
# Create a multidimensional array of coefficients
c = np.arange(8).reshape(2,4)
# Display the array
print("Our Array...")
print(c)
# Check the Dimensions
print("\nDimensions of our Array...")
print(c.ndim)
# Get the Datatype
print("\nDatatype of our Array object...")
print(c.dtype)
# Get the Shape
print("\nShape of our Array object...")
print(c.shape)
# Evaluate Hermite_e series at points x with tensor=True
print("\nResult with tensor=True...")
result = H.hermeval([1,2], c, tensor=True)
print(result)
Our Array... [[0 1 2 3] [4 5 6 7]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (2, 4) Result with tensor=True... [[ 4. 8.] [ 6. 11.] [ 8. 14.] [10. 17.]]
Comparison: Tensor=True vs Tensor=False
The tensor parameter changes how the evaluation is performed ?
import numpy as np
from numpy.polynomial import hermite_e as H
c = np.arange(8).reshape(2,4)
print("Coefficient array:")
print(c)
print("\nShape:", c.shape)
# With tensor=True (default)
result_true = H.hermeval([1,2], c, tensor=True)
print("\nWith tensor=True:")
print("Shape:", result_true.shape)
print("Result:")
print(result_true)
# With tensor=False
result_false = H.hermeval([1,2], c, tensor=False)
print("\nWith tensor=False:")
print("Shape:", result_false.shape)
print("Result:")
print(result_false)
Coefficient array: [[0 1 2 3] [4 5 6 7]] Shape: (2, 4) With tensor=True: Shape: (4, 2) Result: [[ 4. 8.] [ 6. 11.] [ 8. 14.] [10. 17.]] With tensor=False: Shape: (2, 2) Result: [[ 4. 6.] [30. 41.]]
How It Works
When tensor=True, each column of coefficients is evaluated for every element of x, creating a result where each polynomial is evaluated at each point. When tensor=False, the evaluation points are broadcast over the columns, resulting in a different output shape and values.
Conclusion
The hermite_e.hermeval() method provides flexible evaluation of Hermite_e series. Use tensor=True when you need each polynomial evaluated at each point, and tensor=False for broadcasting behavior with multidimensional coefficient arrays.
