MCPcopy Create free account
hub / github.com/numpy/numpy / polyval

Function polyval

numpy/lib/polynomial.py:706–781  ·  view source on GitHub ↗

Evaluate a polynomial at specific values. .. note:: This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in `numpy.polynomial` is preferred. A summary of the differences can be found in the :doc:`transition guide </referen

(p, x)

Source from the content-addressed store, hash-verified

704
705@array_function_dispatch(_polyval_dispatcher)
706def polyval(p, x):
707 """
708 Evaluate a polynomial at specific values.
709
710 .. note::
711 This forms part of the old polynomial API. Since version 1.4, the
712 new polynomial API defined in `numpy.polynomial` is preferred.
713 A summary of the differences can be found in the
714 :doc:`transition guide </reference/routines.polynomials>`.
715
716 If `p` is of length N, this function returns the value:
717
718 ``p[0]*x**(N-1) + p[1]*x**(N-2) + ... + p[N-2]*x + p[N-1]``
719
720 If `x` is a sequence, then ``p(x)`` is returned for each element of ``x``.
721 If `x` is another polynomial then the composite polynomial ``p(x(t))``
722 is returned.
723
724 Parameters
725 ----------
726 p : array_like or poly1d object
727 1D array of polynomial coefficients (including coefficients equal
728 to zero) from highest degree to the constant term, or an
729 instance of poly1d.
730 x : array_like or poly1d object
731 A number, an array of numbers, or an instance of poly1d, at
732 which to evaluate `p`.
733
734 Returns
735 -------
736 values : ndarray or poly1d
737 If `x` is a poly1d instance, the result is the composition of the two
738 polynomials, i.e., `x` is "substituted" in `p` and the simplified
739 result is returned. In addition, the type of `x` - array_like or
740 poly1d - governs the type of the output: `x` array_like => `values`
741 array_like, `x` a poly1d object => `values` is also.
742
743 See Also
744 --------
745 poly1d: A polynomial class.
746
747 Notes
748 -----
749 Horner&#x27;s scheme [1]_ is used to evaluate the polynomial. Even so,
750 for polynomials of high degree the values may be inaccurate due to
751 rounding errors. Use carefully.
752
753 If `x` is a subtype of `ndarray` the return value will be of the same type.
754
755 References
756 ----------
757 .. [1] I. N. Bronshtein, K. A. Semendyayev, and K. A. Hirsch (Eng.
758 trans. Ed.), *Handbook of Mathematics*, New York, Van Nostrand
759 Reinhold Co., 1985, pg. 720.
760
761 Examples
762 --------
763 >>> np.polyval([3,0,1], 5) # 3 * 5**2 + 0 * 5**1 + 1

Callers 2

__call__Method · 0.70
_mac_os_checkFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected