Evaluate a 2-D Chebyshev series on the Cartesian product of x and y in Python

To evaluate a 2-D Chebyshev series on the Cartesian product of x and y, use the polynomial.chebgrid2d(x, y, c) method in Python. The method returns the values of the two-dimensional Chebyshev series at points in the Cartesian product of x and y.

If c has fewer than two dimensions, ones are implicitly appended to its shape to make it 2-D. The shape of the result will be c.shape[2:] + x.shape + y.shape.

Parameters

The function takes three main parameters:

  • x, y − Arrays at which the 2D series is evaluated. 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 multidegree i,j is contained in c[i,j]

Example

Let's create a complete example to evaluate a 2-D Chebyshev series −

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

# 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)

# Evaluate 2-D Chebyshev series on Cartesian product
print("\nResult...\n", C.chebgrid2d([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...
 [[ 6. 10.]
 [11. 18.]]

Understanding the Output

The result is a 2x2 array where each element represents the evaluation of the Chebyshev series at the corresponding Cartesian product point. For coefficient matrix [[0,1],[2,3]] and evaluation points [1,2] for both x and y, the function computes the series values at points (1,1), (1,2), (2,1), and (2,2).

Using Different Evaluation Points

You can evaluate the series at different x and y coordinates −

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

# Same coefficient matrix
c = np.array([[0, 1], [2, 3]])

# Different evaluation points
x_points = [0, 1, 2]
y_points = [0, 1]

result = C.chebgrid2d(x_points, y_points, c)
print("Result with different points:\n", result)
print("Shape:", result.shape)
Result with different points:
 [[1. 2.]
 [3. 6.]
 [9. 18.]]
Shape: (3, 2)

Conclusion

The chebgrid2d() function efficiently evaluates 2-D Chebyshev series on Cartesian products. The output shape depends on the input coordinate arrays, making it useful for evaluating polynomial surfaces over grids of points.

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

189 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements