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 3-D Hermite_e series on the Cartesian product of x, y and z with 2d array of coefficient in Python
To evaluate a 3-D Hermite_e series on the Cartesian product of x, y and z, use the hermite_e.hermegrid3d(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.
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.
Parameters
The parameter c is 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[3:] + x.shape + y.shape + z.shape.
Example
Let's create a 2D coefficient array and evaluate the Hermite_e series ?
import numpy as np
from numpy.polynomial import hermite_e 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_e series on Cartesian product
print("\nResult...\n",H.hermegrid3d([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... [[17. 28.] [28. 46.]]
Understanding the Result
The result is a 2x2 array where each element corresponds to the evaluation of the Hermite_e series at different combinations of the Cartesian product. The coefficient matrix c defines the polynomial terms, and the function evaluates these at all combinations of the input points [1,2] for x, y, and z coordinates.
Different Input Points
You can also use different coordinate values for x, y, and z ?
import numpy as np
from numpy.polynomial import hermite_e as H
# Create coefficient array
c = np.array([[1, 2], [3, 4]])
# Evaluate with different x, y, z values
result = H.hermegrid3d([0, 1], [0, 1], [1], c)
print("Result with different coordinates:")
print(result)
print("\nShape of result:", result.shape)
Result with different coordinates: [[[10. 16.] [16. 26.]]] Shape of result: (1, 2, 2)
Conclusion
The hermegrid3d() method efficiently evaluates 3-D Hermite_e series on Cartesian products. The coefficient array defines the polynomial terms, and the result shape depends on both the coefficient dimensions and input coordinate arrays.
