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

Class poly1d

numpy/lib/polynomial.py:1078–1449  ·  view source on GitHub ↗

A one-dimensional polynomial class. .. 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 </reference/rou

Source from the content-addressed store, hash-verified

1076
1077@set_module('numpy')
1078class poly1d:
1079 """
1080 A one-dimensional polynomial class.
1081
1082 .. note::
1083 This forms part of the old polynomial API. Since version 1.4, the
1084 new polynomial API defined in `numpy.polynomial` is preferred.
1085 A summary of the differences can be found in the
1086 :doc:`transition guide </reference/routines.polynomials>`.
1087
1088 A convenience class, used to encapsulate "natural" operations on
1089 polynomials so that said operations may take on their customary
1090 form in code (see Examples).
1091
1092 Parameters
1093 ----------
1094 c_or_r : array_like
1095 The polynomial&#x27;s coefficients, in decreasing powers, or if
1096 the value of the second parameter is True, the polynomial&#x27;s
1097 roots (values where the polynomial evaluates to 0). For example,
1098 ``poly1d([1, 2, 3])`` returns an object that represents
1099 :math:`x^2 + 2x + 3`, whereas ``poly1d([1, 2, 3], True)`` returns
1100 one that represents :math:`(x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x -6`.
1101 r : bool, optional
1102 If True, `c_or_r` specifies the polynomial&#x27;s roots; the default
1103 is False.
1104 variable : str, optional
1105 Changes the variable used when printing `p` from `x` to `variable`
1106 (see Examples).
1107
1108 Examples
1109 --------
1110 Construct the polynomial :math:`x^2 + 2x + 3`:
1111
1112 >>> p = np.poly1d([1, 2, 3])
1113 >>> print(np.poly1d(p))
1114 2
1115 1 x + 2 x + 3
1116
1117 Evaluate the polynomial at :math:`x = 0.5`:
1118
1119 >>> p(0.5)
1120 4.25
1121
1122 Find the roots:
1123
1124 >>> p.r
1125 array([-1.+1.41421356j, -1.-1.41421356j])
1126 >>> p(p.r)
1127 array([ -4.44089210e-16+0.j, -4.44089210e-16+0.j]) # may vary
1128
1129 These numbers in the previous line represent (0, 0) to machine precision
1130
1131 Show the coefficients:
1132
1133 >>> p.c
1134 array([1, 2, 3])
1135

Callers 15

polyintFunction · 0.85
polyderFunction · 0.85
polyaddFunction · 0.85
polysubFunction · 0.85
polymulFunction · 0.85
polydivFunction · 0.85
__neg__Method · 0.85
__mul__Method · 0.85
__rmul__Method · 0.85
__add__Method · 0.85
__radd__Method · 0.85
__pow__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected