kilojoules
kilojoules

Reputation: 10093

How do I feed numpy.polynomial.chebyshev.Chebyshev coefficients?

How do I feed np.polynomial.Chebyshev coefficients? I'm finding the API to be unintuitive. It looks like it is assuming some coefficient values

> import numpy as np
> xf = 3
> P = np.polynomial.Chebyshev([0, xf]) # domain is [0, xf]
> P(np.linspace(0, 3, 5)) # evaluate at 5 x-points evenly spaced from 0 to 3
array([0.        , 2.35619449, 4.71238898, 7.06858347, 9.42477796])
P(np.linspace(0, 3, 5), [1,2,3]) # evaluate the points with prescribed coefficients, implicitly asking for polynomials of 4 degrees 
TypeError: __call__() takes exactly 2 arguments (3 given)

Upvotes: 0

Views: 1267

Answers (1)

user2357112
user2357112

Reputation: 281529

If you look at the Chebyshev docs, you'll find that the first argument is the coefficients, not the domain. The domain is the optional second argument. For example,

np.polynomial.Chebyshev([0, 3])

is 0*T_0 + 3*T_1.

Upvotes: 2

Related Questions