diff options
author | Stefanie Molin <24376333+stefmolin@users.noreply.github.com> | 2023-04-14 01:22:48 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-13 22:22:48 -0700 |
commit | 3fd058ce9ec610f3a7e04eb0592e5ab1848ee58c (patch) | |
tree | 5fe912f5b2364a148ea3a48d7e5407502488dc4e /numpy/polynomial/_polybase.py | |
parent | d2ae0e759670a8801b7e274112581b87a995c008 (diff) | |
download | numpy-3fd058ce9ec610f3a7e04eb0592e5ab1848ee58c.tar.gz |
DOC: Add example for Polynomial.degree(). (#23530)
Include additional example about 0-coefficients and the trim method.
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Diffstat (limited to 'numpy/polynomial/_polybase.py')
-rw-r--r-- | numpy/polynomial/_polybase.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/numpy/polynomial/_polybase.py b/numpy/polynomial/_polybase.py index a5c7c6415..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 |