MCPcopy Index your code
hub / github.com/numpy/numpy / polyval

Function polyval

numpy/lib/_polynomial_impl.py:714–790  ·  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

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

Callers 2

_mac_os_checkFunction · 0.90
__call__Method · 0.70

Calls 1

zeros_likeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…