Evaluate a 2-D Chebyshev series at points (x, y) with 1D array of coefficient in Python

To evaluate a 2-D Chebyshev series at points (x, y), use the polynomial.chebval2d() method in Python NumPy. The method returns the values of the two-dimensional Chebyshev series at points formed from pairs of corresponding values from x and y. The two-dimensional series is evaluated at the points (x, y), where x and y must have the same shape.

The parameter c is an 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 2, the remaining indices enumerate multiple sets of coefficients.

Syntax

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

Parameters

  • x, y − Array-like coordinates where x and y must have the same shape
  • c − Array of coefficients ordered so that coefficient of term of multi-degree i,j is in c[i,j]

Example

Let's evaluate a 2-D Chebyshev series using a 1D coefficient array ?

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

# Create a 1d array of coefficients
c = np.array([3, 5])

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

# To evaluate a 2-D Chebyshev series at points (x, y)
print("\nResult...")
print(C.chebval2d([1,2], [1,2], c))
Our Array...
[3 5]

Dimensions of our Array...
1

Datatype of our Array object...
int64

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

Result...
[21. 34.]

Using 2D Coefficient Array

Here's an example with a proper 2D coefficient array ?

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

# Create a 2D array of coefficients
c = np.array([[1, 2], [3, 4]])

print("2D Coefficient Array:")
print(c)

# Evaluate at specific points
x_points = [0, 1]
y_points = [0, 1]

result = C.chebval2d(x_points, y_points, c)
print("\nEvaluating at points (0,0) and (1,1):")
print(result)
2D Coefficient Array:
[[1 2]
 [3 4]]

Evaluating at points (0,0) and (1,1):
[1. 10.]

Key Points

  • The x and y coordinates must have the same shape
  • For 1D coefficient arrays, the function treats it as coefficients for different degrees
  • The function evaluates the series at corresponding pairs of (x, y) points
  • If x or y is a list or tuple, it's converted to an ndarray

Conclusion

The chebval2d() function efficiently evaluates 2D Chebyshev series at specified coordinate pairs. Use proper 2D coefficient arrays for multi-degree polynomial evaluation, ensuring x and y coordinates have matching shapes.

Updated on: 2026-03-26T19:46:14+05:30

225 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements