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 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.
Syntax
numpy.polynomial.hermite_e.hermegrid3d(x, y, z, c)
Parameters
The parameters are x, y, 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.
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 3D coefficient array and evaluate the Hermite_e series ?
import numpy as np
from numpy.polynomial import hermite_e as H
# Create a 3D array of coefficients
c = np.arange(16).reshape(2,2,4)
# Display the array
print("Coefficient Array:")
print(c)
# Check array properties
print(f"\nDimensions: {c.ndim}")
print(f"Datatype: {c.dtype}")
print(f"Shape: {c.shape}")
# Evaluate 3-D Hermite_e series on Cartesian product
result = H.hermegrid3d([1,2], [1,2], [1,2], c)
print("\nResult:")
print(result)
Coefficient Array: [[[ 0 1 2 3] [ 4 5 6 7]] [[ 8 9 10 11] [12 13 14 15]]] Dimensions: 3 Datatype: int64 Shape: (2, 2, 4) Result: [[[-20. 248.] [-30. 404.]] [[-30. 436.] [-45. 702.]]]
How It Works
The hermegrid3d() function evaluates the 3D Hermite_e polynomial at all combinations of the input points. With input arrays [1,2] for each dimension, it creates a 2×2×2 grid of evaluation points and returns the corresponding polynomial values based on the coefficient array.
Different Input Arrays
You can use different arrays for x, y, and z coordinates ?
import numpy as np
from numpy.polynomial import hermite_e as H
# Create coefficient array
c = np.arange(8).reshape(2,2,2)
print("Coefficient Array:")
print(c)
# Use different coordinate arrays
x_vals = [0, 1]
y_vals = [0, 1, 2]
z_vals = [1]
result = H.hermegrid3d(x_vals, y_vals, z_vals, c)
print(f"\nResult shape: {result.shape}")
print("Result:")
print(result)
Coefficient Array: [[[0 1] [2 3]] [[4 5] [6 7]]] Result shape: (2, 3, 1) Result: [[[6.] [8.] [14.]]]
Conclusion
The hermegrid3d() method efficiently evaluates 3D Hermite_e series on Cartesian products. It's useful for multidimensional polynomial interpolation and approximation problems in scientific computing.
