numpy.polyval

numpy.polyval(p, x)

Evaluate a polynomial at specific values.

If p is of length N, this function returns the value:

p[0]*(x**N-1) + p[1]*(x**N-2) + ... + p[N-2]*x + p[N-1]

If x is a sequence then p(x) will be returned for all elements of x. If x is another polynomial then the composite polynomial p(x) will be returned.

Parameters:

p : {array_like, poly1d}

1D array of polynomial coefficients from highest degree to zero or an instance of poly1d.

x : {array_like, poly1d}

A number, a 1D array of numbers, or an instance of poly1d.

Returns:

values : {ndarray, poly1d}

If either p or x is an instance of poly1d, then an instance of poly1d is returned, otherwise a 1D array is returned. In the case where x is a poly1d, the result is the composition of the two polynomials, i.e., substitution is used.

See also

poly1d
A polynomial class.

Notes

Horner’s method is used to evaluate the polynomial. Even so, for polynomials of high degree the values may be inaccurate due to rounding errors. Use carefully.

Examples

>>> np.polyval([3,0,1], 5)  # 3 * 5**2 + 0 * 5**1 + 1
76

Previous topic

numpy.poly1d

Next topic

numpy.poly

This Page

Quick search