Evaluate a 2-D Hermite series at points (x,y) with 3D array of coefficient using NumPy in Python

Evaluate a 2-D Hermite series at points (x,y) with 3D array of coefficient using NumPy in Python

To evaluate a 2-D Hermite series at points (x,y) using a 3D array of coefficients, you would essentially be dealing with a tensor product of 1-D Hermite polynomials. NumPy's polynomial.hermite_e module provides the tools needed, but a 2-D Hermite series evaluation isn't directly provided.

Here's a step-by-step approach on how to achieve this:

  1. Prepare your 3D array of coefficients. The dimensions of this array will represent the order of the Hermite polynomial along each dimension (x, y).
  2. Use hermeval for each 1-D array along the x and y dimensions to get intermediate evaluations.
  3. Multiply and sum up the results to get the final evaluation.

Here's some code to demonstrate this:

import numpy as np def hermeval2d(x, y, coef3d): """ Evaluate a 2-D Hermite series at points (x,y) using a 3D array of coefficients. """ # Get the shape of the coefficient array k, l, m = coef3d.shape # Calculate the intermediate 1-D Hermite evaluations evals_x = np.array([np.polynomial.hermite_e.hermeval(x, coef3d[i,:,:]) for i in range(k)]) evals_y = np.array([np.polynomial.hermite_e.hermeval(y, coef3d[:,j,:]) for j in range(l)]) # Combine the results for 2D evaluation result = np.tensordot(evals_x, evals_y, axes=0) return result # Define a 3D array of coefficients for the Hermite series coeffs = np.random.rand(3,3,3) # Here, just using random coefficients for demonstration # Evaluate at a single point (x, y) x, y = 0.5, 0.6 result = hermeval2d(x, y, coeffs) print(result) 

Note: This approach assumes a fairly dense grid of points. If you have a sparser set of (x, y) values, you might want to loop through them and evaluate the 2-D Hermite series at each point separately.


More Tags

viewdidappear navigationbar windows-mobile dyld can-bus configuration-files robo3t nuget-package uicollectionviewcell common-table-expression

More Programming Guides

Other Guides

More Programming Examples