diff options
Diffstat (limited to 'numpy/polynomial')
-rw-r--r-- | numpy/polynomial/_polybase.py | 24 | ||||
-rw-r--r-- | numpy/polynomial/chebyshev.py | 6 | ||||
-rw-r--r-- | numpy/polynomial/hermite.py | 6 | ||||
-rw-r--r-- | numpy/polynomial/hermite_e.py | 6 | ||||
-rw-r--r-- | numpy/polynomial/laguerre.py | 6 | ||||
-rw-r--r-- | numpy/polynomial/legendre.py | 6 | ||||
-rw-r--r-- | numpy/polynomial/polynomial.py | 6 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_printing.py | 4 |
8 files changed, 63 insertions, 1 deletions
diff --git a/numpy/polynomial/_polybase.py b/numpy/polynomial/_polybase.py index 3bea91dd2..9730574cf 100644 --- a/numpy/polynomial/_polybase.py +++ b/numpy/polynomial/_polybase.py @@ -682,6 +682,28 @@ class ABCPolyBase(abc.ABC): degree : int Degree of the series, one less than the number of coefficients. + Examples + -------- + + Create a polynomial object for ``1 + 7*x + 4*x**2``: + + >>> poly = np.polynomial.Polynomial([1, 7, 4]) + >>> print(poly) + 1.0 + 7.0·x + 4.0·x² + >>> poly.degree() + 2 + + Note that this method does not check for non-zero coefficients. + You must trim the polynomial to remove any trailing zeroes: + + >>> poly = np.polynomial.Polynomial([1, 7, 0]) + >>> print(poly) + 1.0 + 7.0·x + 0.0·x² + >>> poly.degree() + 2 + >>> poly.trim().degree() + 1 + """ return len(self) - 1 @@ -887,7 +909,7 @@ class ABCPolyBase(abc.ABC): """Return the roots of the series polynomial. Compute the roots for the series. Note that the accuracy of the - roots decrease the further outside the domain they lie. + roots decreases the further outside the `domain` they lie. Returns ------- diff --git a/numpy/polynomial/chebyshev.py b/numpy/polynomial/chebyshev.py index c663ffab0..efbe13e0c 100644 --- a/numpy/polynomial/chebyshev.py +++ b/numpy/polynomial/chebyshev.py @@ -2012,6 +2012,12 @@ class Chebyshev(ABCPolyBase): Window, see `domain` for its use. The default value is [-1, 1]. .. versionadded:: 1.6.0 + symbol : str, optional + Symbol used to represent the independent variable in string + representations of the polynomial expression, e.g. for printing. + The symbol must be a valid Python identifier. Default value is 'x'. + + .. versionadded:: 1.24 """ # Virtual Functions diff --git a/numpy/polynomial/hermite.py b/numpy/polynomial/hermite.py index e20339121..210df25f5 100644 --- a/numpy/polynomial/hermite.py +++ b/numpy/polynomial/hermite.py @@ -1675,6 +1675,12 @@ class Hermite(ABCPolyBase): Window, see `domain` for its use. The default value is [-1, 1]. .. versionadded:: 1.6.0 + symbol : str, optional + Symbol used to represent the independent variable in string + representations of the polynomial expression, e.g. for printing. + The symbol must be a valid Python identifier. Default value is 'x'. + + .. versionadded:: 1.24 """ # Virtual Functions diff --git a/numpy/polynomial/hermite_e.py b/numpy/polynomial/hermite_e.py index 182c562c2..bdf29405b 100644 --- a/numpy/polynomial/hermite_e.py +++ b/numpy/polynomial/hermite_e.py @@ -1667,6 +1667,12 @@ class HermiteE(ABCPolyBase): Window, see `domain` for its use. The default value is [-1, 1]. .. versionadded:: 1.6.0 + symbol : str, optional + Symbol used to represent the independent variable in string + representations of the polynomial expression, e.g. for printing. + The symbol must be a valid Python identifier. Default value is 'x'. + + .. versionadded:: 1.24 """ # Virtual Functions diff --git a/numpy/polynomial/laguerre.py b/numpy/polynomial/laguerre.py index 2eacceced..925d4898e 100644 --- a/numpy/polynomial/laguerre.py +++ b/numpy/polynomial/laguerre.py @@ -1623,6 +1623,12 @@ class Laguerre(ABCPolyBase): Window, see `domain` for its use. The default value is [0, 1]. .. versionadded:: 1.6.0 + symbol : str, optional + Symbol used to represent the independent variable in string + representations of the polynomial expression, e.g. for printing. + The symbol must be a valid Python identifier. Default value is 'x'. + + .. versionadded:: 1.24 """ # Virtual Functions diff --git a/numpy/polynomial/legendre.py b/numpy/polynomial/legendre.py index 028e2fe7b..8e9c19d94 100644 --- a/numpy/polynomial/legendre.py +++ b/numpy/polynomial/legendre.py @@ -1636,6 +1636,12 @@ class Legendre(ABCPolyBase): Window, see `domain` for its use. The default value is [-1, 1]. .. versionadded:: 1.6.0 + symbol : str, optional + Symbol used to represent the independent variable in string + representations of the polynomial expression, e.g. for printing. + The symbol must be a valid Python identifier. Default value is 'x'. + + .. versionadded:: 1.24 """ # Virtual Functions diff --git a/numpy/polynomial/polynomial.py b/numpy/polynomial/polynomial.py index d102f5a30..ceadff0bf 100644 --- a/numpy/polynomial/polynomial.py +++ b/numpy/polynomial/polynomial.py @@ -1489,6 +1489,12 @@ class Polynomial(ABCPolyBase): Window, see `domain` for its use. The default value is [-1, 1]. .. versionadded:: 1.6.0 + symbol : str, optional + Symbol used to represent the independent variable in string + representations of the polynomial expression, e.g. for printing. + The symbol must be a valid Python identifier. Default value is 'x'. + + .. versionadded:: 1.24 """ # Virtual Functions diff --git a/numpy/polynomial/tests/test_printing.py b/numpy/polynomial/tests/test_printing.py index 990a0d179..6f2a5092d 100644 --- a/numpy/polynomial/tests/test_printing.py +++ b/numpy/polynomial/tests/test_printing.py @@ -478,6 +478,10 @@ class TestPrintOptions: are too small or too large. """ + @pytest.fixture(scope='class', autouse=True) + def use_ascii(self): + poly.set_default_printstyle('ascii') + def test_str(self): p = poly.Polynomial([1/2, 1/7, 1/7*10**8, 1/7*10**9]) assert_equal(str(p), '0.5 + 0.14285714 x + 14285714.28571429 x**2 ' |