Evaluate a 2-D Chebyshev series on the Cartesian product of x and y with 3d array of coefficient in Python

To evaluate a 2-D Chebyshev series on the Cartesian product of x and y with a 3D array of coefficients, use the numpy.polynomial.chebyshev.chebgrid2d() method. This function computes the values of a two-dimensional Chebyshev series at points in the Cartesian product of x and y arrays.

Syntax

numpy.polynomial.chebyshev.chebgrid2d(x, y, c)

Parameters

x, y: Arrays of coordinates. If x or y is a list or tuple, it is first converted to an ndarray. The Chebyshev series is evaluated at points in the Cartesian product of x and y.

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.

How It Works

When c is a 3D array, the function evaluates multiple 2D Chebyshev series simultaneously. The shape of the result will be c.shape[2:] + x.shape + y.shape. If c has fewer than two dimensions, ones are implicitly appended to make it 2-D.

Example

import numpy as np
from numpy.polynomial import chebyshev as C

# Create a 3D array of coefficients
c = np.arange(24).reshape(2, 2, 6)

# Display the coefficient array
print("Coefficient Array:")
print("Shape:", c.shape)
print("Dimensions:", c.ndim)
print(c)
Coefficient Array:
Shape: (2, 2, 6)
Dimensions: 3
[[[ 0  1  2  3  4  5]
  [ 6  7  8  9 10 11]]

 [[12 13 14 15 16 17]
  [18 19 20 21 22 23]]]

Now evaluate the 2D Chebyshev series on the Cartesian product:

import numpy as np
from numpy.polynomial import chebyshev as C

# Create coefficient array
c = np.arange(24).reshape(2, 2, 6)

# Define x and y coordinates
x = [1, 2]
y = [1, 2]

# Evaluate 2D Chebyshev series
result = C.chebgrid2d(x, y, c)

print("Result shape:", result.shape)
print("Result:")
print(result)
Result shape: (6, 2, 2)
Result:
[[[ 36.  60.]
  [ 66. 108.]]

 [[ 40.  66.]
  [ 72. 117.]]

 [[ 44.  72.]
  [ 78. 126.]]

 [[ 48.  78.]
  [ 84. 135.]]

 [[ 52.  84.]
  [ 90. 144.]]

 [[ 56.  90.]
  [ 96. 153.]]]

Understanding the Output

The result has shape (6, 2, 2) because:

  • The first dimension (6) comes from c.shape[2] - representing 6 different coefficient sets
  • The remaining dimensions (2, 2) come from the Cartesian product of x and y, each with 2 elements
  • Each 2×2 matrix represents the evaluation at all combinations of x and y values for one coefficient set

Conclusion

The chebgrid2d() function efficiently evaluates multiple 2D Chebyshev series when working with 3D coefficient arrays. The output shape follows the pattern c.shape[2:] + x.shape + y.shape, making it useful for batch evaluations of polynomial series.

Updated on: 2026-03-26T19:47:27+05:30

215 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements