Evaluate a 3D Laguerre series at points (x,y,z) with 2D array of coefficient in Python

To evaluate a 3D Laguerre series at points (x,y,z), use the polynomial.laguerre.lagval3d() method in Python NumPy. The method returns the values of the multidimensional polynomial on points formed with triples of corresponding values from x, y, and z.

If c has fewer than 3 dimensions, ones are implicitly appended to its shape to make it 3-D. The shape of the result will be c.shape[3:] + x.shape. The 1st parameter is x, y, z. The three dimensional series is evaluated at the points (x, y, z), where x, y, and z must have the same shape.

Syntax

numpy.polynomial.laguerre.lagval3d(x, y, z, c)

Parameters

x, y, z: 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.

c: An array of coefficients ordered so that the coefficient of the term of multi-degree 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.

Example

Let's create a 2D array of coefficients and evaluate the 3D Laguerre series ?

import numpy as np
from numpy.polynomial import laguerre as L

# Create a 2d array of coefficients
c = np.arange(4).reshape(2,2)

# Display the array
print("Our Array...\n",c)

# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)

# Get the Shape
print("\nShape of our Array object...\n",c.shape)

# To evaluate a 3D Laguerre series at points (x,y,z), use the polynomial.laguerre.lagval3d() method
print("\nResult...\n",L.lagval3d([1,2],[1,2],[1,2], c))
Our Array...
 [[0 1]
 [2 3]]

Dimensions of our Array...
2

Datatype of our Array object...
int64

Shape of our Array object...
(2, 2)

Result...
 [0. 0.]

Working with Different Point Values

You can evaluate the series at different coordinate points ?

import numpy as np
from numpy.polynomial import laguerre as L

# Create a 2d coefficient array
c = np.array([[1, 2], [3, 4]])
print("Coefficient array:\n", c)

# Evaluate at single point
result1 = L.lagval3d(0, 0, 0, c)
print("\nResult at (0,0,0):", result1)

# Evaluate at multiple points
x = [0, 1]
y = [0, 1] 
z = [0, 1]
result2 = L.lagval3d(x, y, z, c)
print("Result at multiple points:", result2)
Coefficient array:
 [[1 2]
 [3 4]]

Result at (0,0,0): 1.0

Result at multiple points: [1. 0.]

Understanding the 3D Evaluation

The 3D Laguerre series uses the tensor product of Laguerre polynomials. For a 2D coefficient array, the missing dimension is implicitly extended ?

import numpy as np
from numpy.polynomial import laguerre as L

# Create different coefficient arrays
c1 = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])  # 3D array
c2 = np.array([[1, 2], [3, 4]])  # 2D array (extended to 3D)

print("3D coefficient shape:", c1.shape)
print("2D coefficient shape:", c2.shape)

# Evaluate at the same points
x, y, z = 0.5, 0.5, 0.5
result1 = L.lagval3d(x, y, z, c1)
result2 = L.lagval3d(x, y, z, c2)

print("Result with 3D coefficients:", result1)
print("Result with 2D coefficients:", result2)
3D coefficient shape: (2, 2, 2)
2D coefficient shape: (2, 2)

Result with 3D coefficients: 2.0625
Result with 2D coefficients: 0.5625

Conclusion

The lagval3d() function efficiently evaluates 3D Laguerre series at specified coordinate points. For 2D coefficient arrays, the function automatically extends them to 3D by appending ones to the shape, making it versatile for different dimensional inputs.

Updated on: 2026-03-26T20:34:03+05:30

201 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements