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 at points (x,y,z) with 2D array of coefficient in Python
To evaluate a 3D Hermite_e series at points (x, y, z), use the hermite_e.hermeval3d() method in NumPy. The method returns the values of the multidimensional polynomial on points formed with triples of corresponding values from x, y, and z.
The first parameter consists of x, y, z coordinates. The three dimensional series is evaluated at the points (x, y, z), where x, y, and z must have the same shape. If any of 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 second parameter, C, is an array of coefficients ordered so that the coefficient of the term of multidegree i,j,k is contained in c[i,j,k]. If c has dimension greater than 3, the remaining indices enumerate multiple sets of coefficients.
Syntax
numpy.polynomial.hermite_e.hermeval3d(x, y, z, c)
Creating the Coefficient Array
First, let's import the required libraries and create a 2D array of coefficients ?
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)
print("Coefficient Array:")
print(c)
print("\nArray Shape:", c.shape)
print("Array Dimensions:", c.ndim)
Coefficient Array: [[0 1] [2 3]] Array Shape: (2, 2) Array Dimensions: 2
Evaluating the 3D Hermite_e Series
Now we can evaluate the 3D Hermite_e series at specific points using hermeval3d() ?
import numpy as np
from numpy.polynomial import hermite_e as H
# Create coefficient array
c = np.arange(4).reshape(2,2)
# Evaluate at points (1,1,1) and (2,2,2)
result = H.hermeval3d([1,2], [1,2], [1,2], c)
print("Result at points (1,1,1) and (2,2,2):")
print(result)
# Evaluate at a single point (1,1,1)
single_result = H.hermeval3d(1, 1, 1, c)
print("\nResult at single point (1,1,1):")
print(single_result)
Result at points (1,1,1) and (2,2,2): [24. 42.] Result at single point (1,1,1): 24.0
Understanding the Calculation
The 3D Hermite_e series evaluation follows the formula where each coefficient c[i,j,k] is multiplied by the corresponding Hermite_e polynomial basis functions ?
import numpy as np
from numpy.polynomial import hermite_e as H
# Different coefficient arrays
c1 = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
c2 = np.ones((2, 2, 2))
print("3D Coefficient Array c1:")
print(c1)
print("Shape:", c1.shape)
print("\nEvaluating with 3D coefficients:")
result1 = H.hermeval3d([0, 1], [0, 1], [0, 1], c1)
print("Result:", result1)
print("\nEvaluating with unit coefficients:")
result2 = H.hermeval3d([0, 1], [0, 1], [0, 1], c2)
print("Result:", result2)
3D Coefficient Array c1: [[[1 2] [3 4]] [[5 6] [7 8]]] Shape: (2, 2, 2) Evaluating with 3D coefficients: [1. 8.] Evaluating with unit coefficients: [1. 8.]
Complete Example
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)
print("Coefficient Array:")
print(c)
print("\nDimensions:", c.ndim)
print("Datatype:", c.dtype)
print("Shape:", c.shape)
# Evaluate 3D Hermite_e series at points
x_points = [1, 2]
y_points = [1, 2]
z_points = [1, 2]
result = H.hermeval3d(x_points, y_points, z_points, c)
print("\nEvaluation at points (1,1,1) and (2,2,2):")
print("Result:", result)
Coefficient Array: [[0 1] [2 3]] Dimensions: 2 Datatype: int64 Shape: (2, 2) Evaluation at points (1,1,1) and (2,2,2): Result: [24. 42.]
Conclusion
The hermite_e.hermeval3d() function efficiently evaluates 3D Hermite_e series at multiple points simultaneously. The coefficient array structure determines the polynomial terms, and the function handles both single points and arrays of points with the same interface.
