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 2-D Laguerre series on the Cartesian product of x and y with 3d array of coefficient in Python
To evaluate a 2-D Laguerre series on the Cartesian product of x and y with a 3D array of coefficients, use the numpy.polynomial.laguerre.laggrid2d() method in Python. This method returns the values of the two-dimensional Laguerre series at points in the Cartesian product of x and y.
The coefficient array c should be ordered so that the coefficient of the term of multi-degree i,j is contained in c[i,j]. When c has more than two dimensions, the additional indices enumerate multiple sets of coefficients, allowing for batch evaluation.
Syntax
numpy.polynomial.laguerre.laggrid2d(x, y, c)
Parameters
x, y ? Arrays of point coordinates. If they are lists or tuples, they are converted to ndarrays.
c ? Array of coefficients with shape (M, N, ...). The first two dimensions correspond to the Laguerre polynomial degrees.
Example
Let's evaluate a 2-D Laguerre series using a 3D coefficient array ?
import numpy as np
from numpy.polynomial import laguerre as L
# Create a 3D array of coefficients
c = np.arange(24).reshape(2, 2, 6)
print("Coefficient Array:")
print("Shape:", c.shape)
print("Array:\n", c)
# Define evaluation points
x_points = [1, 2]
y_points = [1, 2]
# Evaluate the 2-D Laguerre series
result = L.laggrid2d(x_points, y_points, c)
print("\nResult shape:", result.shape)
print("Result:\n", result)
Coefficient Array: Shape: (2, 2, 6) Array: [[[ 0 1 2 3 4 5] [ 6 7 8 9 10 11]] [[12 13 14 15 16 17] [18 19 20 21 22 23]]] Result shape: (6, 2, 2) Result: [[[ 0. -6.] [-12. 0.]] [[ 1. -6.] [-12. 0.]] [[ 2. -6.] [-12. 0.]] [[ 3. -6.] [-12. 0.]] [[ 4. -6.] [-12. 0.]] [[ 5. -6.] [-12. 0.]]]
Understanding the Output
The result has shape (6, 2, 2) because:
- The coefficient array has shape
(2, 2, 6) - We evaluate at 2 x-points and 2 y-points
- The output shape follows:
c.shape[2:] + x.shape + y.shape = (6,) + (2,) + (2,) = (6, 2, 2)
Each of the 6 coefficient sets produces a (2, 2) result matrix corresponding to the Cartesian product of the evaluation points.
Conclusion
The laggrid2d() method efficiently evaluates 2-D Laguerre series on Cartesian products. When using 3D coefficient arrays, it performs batch evaluation across multiple coefficient sets, making it useful for processing multiple series simultaneously.
