Evaluate a Chebyshev series at points x broadcast over the columns of the coefficient in Python

To evaluate a Chebyshev series at points x, use the chebyshev.chebval() method in Python NumPy. This function allows you to evaluate Chebyshev polynomials with given coefficients at specific points, with control over how broadcasting is handled.

Syntax

numpy.polynomial.chebyshev.chebval(x, c, tensor=True)

Parameters

x: If x is a list or tuple, it is converted to an ndarray, otherwise it is left unchanged and treated as a scalar. The elements must support addition and multiplication with themselves and with the elements of c.

c: An array of coefficients ordered so that the coefficients for terms of degree n are contained in c[n]. If c is multidimensional, the remaining indices enumerate multiple polynomials. In the two-dimensional case, the coefficients may be thought of as stored in the columns of c.

tensor: If True (default), the shape of the coefficient array is extended with ones on the right, one for each dimension of x. If False, x is broadcast over the columns of c for the evaluation.

Example with tensor=False

Let's create a multidimensional coefficient array and evaluate it at specific points ?

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

# Create a multidimensional array of coefficients
c = np.arange(6).reshape(3, 2)
print("Coefficient Array:")
print(c)

# Check array properties
print("\nDimensions:", c.ndim)
print("Datatype:", c.dtype)
print("Shape:", c.shape)

# Evaluate Chebyshev series at points [1, 2] with tensor=False
result = C.chebval([1, 2], c, tensor=False)
print("\nResult (tensor=False):", result)
Coefficient Array:
[[0 1]
 [2 3]
 [4 5]]

Dimensions: 2
Datatype: int64
Shape: (3, 2)

Result (tensor=False): [ 6. 42.]

Comparison: tensor=True vs tensor=False

Let's compare the behavior with both tensor settings ?

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

c = np.arange(6).reshape(3, 2)
x = [1, 2]

# With tensor=True (default)
result_tensor_true = C.chebval(x, c, tensor=True)
print("tensor=True result shape:", result_tensor_true.shape)
print("tensor=True result:\n", result_tensor_true)

# With tensor=False
result_tensor_false = C.chebval(x, c, tensor=False)
print("\ntensor=False result shape:", result_tensor_false.shape)
print("tensor=False result:", result_tensor_false)
tensor=True result shape: (2, 2)
tensor=True result:
 [[ 6.  7.]
 [42. 47.]]

tensor=False result shape: (2,)
tensor=False result: [ 6. 42.]

How It Works

When tensor=False, the function broadcasts x over the columns of the coefficient array. For our example:

  • First column [0, 2, 4]: evaluates at x=1 to give 6
  • Second column [1, 3, 5]: evaluates at x=2 to give 42

When tensor=True, each point in x is evaluated against each column separately, creating a 2D result.

Conclusion

Use chebval() with tensor=False to broadcast evaluation points over coefficient columns efficiently. This is particularly useful for evaluating multiple Chebyshev series simultaneously at corresponding points.

Updated on: 2026-03-26T19:45:20+05:30

196 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements