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
Selected Reading
Evaluate a 3-D Hermite series on the Cartesian product of x, y and z with 4d array of coefficient in Python
To evaluate a 3-D Hermite series on the Cartesian product of x, y and z, use the hermite.hermgrid3d(x, y, z, c) method in Python. This method evaluates a three-dimensional Hermite polynomial at all combinations of points from the input arrays.
Parameters
The method takes four parameters:
- x, y, z − The three coordinate arrays. The series is evaluated at points in the Cartesian product of x, y, and z. If any parameter is a list or tuple, it's converted to an ndarray.
-
c − A 4D array of coefficients where
c[i,j,k,:]contains coefficients for terms of degree i,j,k. The shape of the result will bec.shape[3:] + x.shape + y.shape + z.shape.
Example
Let's create a 4D coefficient array and evaluate the Hermite series:
import numpy as np
from numpy.polynomial import hermite as H
# Create a 4d array of coefficients
c = np.arange(48).reshape(2,2,6,2)
# Display the array properties
print("Coefficient Array Shape:", c.shape)
print("Dimensions:", c.ndim)
print("Datatype:", c.dtype)
# Evaluate 3-D Hermite series on Cartesian product
result = H.hermgrid3d([1,2], [1,2], [1,2], c)
print("\nResult shape:", result.shape)
print("Result:\n", result)
Coefficient Array Shape: (2, 2, 6, 2)
Dimensions: 4
Datatype: int64
Result shape: (2, 2, 2, 2, 2)
Result:
[[[[[ -8100. 32472.]
[-14148. 56976.]]
[[-14796. 59832.]
[-25740. 104480.]]]
[[[ -8343. 33543.]
[-14553. 58761.]]
[[-15201. 61617.]
[-26415. 107455.]]]]]
How It Works
The function evaluates the 3-D Hermite polynomial:
The result has shape (2, 2, 2, 2, 2) because:
- Coefficient array shape:
(2, 2, 6, 2)? last dimension gives us 2 - Each coordinate array
[1,2]has length 2 - Final shape:
c.shape[3:] + x.shape + y.shape + z.shape = (2,) + (2,) + (2,) + (2,) = (2,2,2,2)
Conclusion
The hermgrid3d() function efficiently evaluates 3-D Hermite series on Cartesian products. The result shape depends on both the coefficient array dimensions and input coordinate array shapes.
Advertisements
