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 2D Laguerre series at points (x,y) with 3D array of coefficients in Python
To evaluate a 2D Laguerre series at points (x,y), use the polynomial.laguerre.lagval2d() method in NumPy. This method returns values of the two-dimensional polynomial at points formed with pairs of corresponding values from x and y coordinates.
Syntax
numpy.polynomial.laguerre.lagval2d(x, y, c)
Parameters
x, y: The two-dimensional series is evaluated at points (x, y), where x and y must have the same shape. If x or y is a list or tuple, it is first converted to an ndarray.
c: Array of coefficients ordered so that the coefficient of the term of multi-degree i,j is contained in c[i,j]. If c has dimension greater than two, the remaining indices enumerate multiple sets of coefficients.
Example
Let's create a 3D array of coefficients and evaluate the 2D Laguerre series at specific points ?
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)
# Display the array
print("Our Array...")
print(c)
# Check the Dimensions
print("\nDimensions of our Array...")
print(c.ndim)
# Get the Datatype
print("\nDatatype of our Array object...")
print(c.dtype)
# Get the Shape
print("\nShape of our Array object...")
print(c.shape)
# Evaluate 2D Laguerre series at points (1,1) and (2,2)
print("\nResult...")
print(L.lagval2d([1,2], [1,2], c))
Our 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]]] Dimensions of our Array... 3 Datatype of our Array object... int64 Shape of our Array object... (2, 2, 6) Result... [[ 0. 1.] [ 1. 0.] [ 2. 0.] [ 3. 0.] [ 4. 0.] [ 5. 0.]]
How It Works
The 3D coefficient array has shape (2, 2, 6), where the first two dimensions define the polynomial degrees and the third dimension contains 6 different coefficient sets. The function evaluates each set of coefficients at the given (x,y) points, returning a 6×2 array where each row corresponds to one coefficient set.
Different Point Evaluation
You can evaluate at different coordinate combinations ?
import numpy as np
from numpy.polynomial import laguerre as L
# Create coefficient array
c = np.arange(8).reshape(2,2,2)
print("Coefficients shape:", c.shape)
print("Coefficients:")
print(c)
# Evaluate at multiple points
x_vals = [0, 1, 2]
y_vals = [0, 1, 2]
result = L.lagval2d(x_vals, y_vals, c)
print("\nEvaluation at points (0,0), (1,1), (2,2):")
print(result)
Coefficients shape: (2, 2, 2) Coefficients: [[[0 1] [2 3]] [[4 5] [6 7]]] Evaluation at points (0,0), (1,1), (2,2): [[0. 1.] [6. 7.]]
Conclusion
The lagval2d() function efficiently evaluates 2D Laguerre polynomials at given coordinate points using coefficient arrays. It handles multiple coefficient sets simultaneously, making it useful for batch polynomial evaluations in scientific computing applications.
