Paul Jurczak
Paul Jurczak

Reputation: 8173

What is the equivalent of np.polyval in the new np.polynomial API?

I can't find a direct answer in NumPy documentation. This snippet will populate y with polynomial p values on domain x:

p = [1, 2, 3]
x = np.linspace(0, 1, 10)
y = [np.polyval(p, i) for i in x]

What is the new API equivalent when p = Polynomial(p)?

Upvotes: 2

Views: 64

Answers (1)

Michael Cao
Michael Cao

Reputation: 3609

You can simply evaluate values with p(x). Documentation can be found on "Using the convenience classes" under "Evaluation":

p = [1, 2, 3]

p = np.polynomial.Polynomial(p)

x = np.linspace(0, 1, 10)

y = p(x)

Note: Coefficients are in reverse order compared to legacy API i.e. coefficients go from lowest order to highest order such that p[i] is the ith-order term.

Upvotes: 3

Related Questions