summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-08-10 11:04:18 -0500
committerEric Wieser <wieser.eric@gmail.com>2017-08-10 12:26:20 -0500
commitcc781ee138982335f9a7986a65ac05ee938f9b14 (patch)
tree6e36051fbb6987721d87b737409671b25574a92e
parent9e05bc3f5197ec465362f651b73f01b6476625d5 (diff)
downloadnumpy-cc781ee138982335f9a7986a65ac05ee938f9b14.tar.gz
ENH: Show domain and window as kwargs in repr
Also, update the docs with this new repr
-rw-r--r--doc/release/1.14.0-notes.rst8
-rw-r--r--doc/source/reference/routines.polynomials.classes.rst48
-rw-r--r--numpy/polynomial/_polybase.py2
-rw-r--r--numpy/polynomial/chebyshev.py4
-rw-r--r--numpy/polynomial/legendre.py6
5 files changed, 38 insertions, 30 deletions
diff --git a/doc/release/1.14.0-notes.rst b/doc/release/1.14.0-notes.rst
index 0ca7b7ddf..d00522d4c 100644
--- a/doc/release/1.14.0-notes.rst
+++ b/doc/release/1.14.0-notes.rst
@@ -141,6 +141,14 @@ Because ``np.tensordot`` uses BLAS when possible, that will speed up execution.
By default, ``np.einsum`` will also attempt optimization as the overhead is
small relative to the potential improvement in speed.
+The ``repr`` of ``np.polynomial`` classes is more explicit
+----------------------------------------------------------
+It now shows the domain and window parameters as keyword arguments to make
+them more clear::
+
+ >>> np.polynomial.Polynomial(range(4))
+ Polynomial([ 0., 1., 2., 3.], domain=[-1, 1], window=[-1, 1])
+
Changes
=======
diff --git a/doc/source/reference/routines.polynomials.classes.rst b/doc/source/reference/routines.polynomials.classes.rst
index 0db77eb7c..f44ddd46c 100644
--- a/doc/source/reference/routines.polynomials.classes.rst
+++ b/doc/source/reference/routines.polynomials.classes.rst
@@ -52,7 +52,7 @@ the conventional Polynomial class because of its familiarity::
>>> from numpy.polynomial import Polynomial as P
>>> p = P([1,2,3])
>>> p
- Polynomial([ 1., 2., 3.], [-1., 1.], [-1., 1.])
+ Polynomial([ 1., 2., 3.], domain=[-1, 1], window=[-1, 1])
Note that there are three parts to the long version of the printout. The
first is the coefficients, the second is the domain, and the third is the
@@ -77,19 +77,19 @@ we ignore them and run through the basic algebraic and arithmetic operations.
Addition and Subtraction::
>>> p + p
- Polynomial([ 2., 4., 6.], [-1., 1.], [-1., 1.])
+ Polynomial([ 2., 4., 6.], domain=[-1, 1], window=[-1, 1])
>>> p - p
- Polynomial([ 0.], [-1., 1.], [-1., 1.])
+ Polynomial([ 0.], domain=[-1, 1], window=[-1, 1])
Multiplication::
>>> p * p
- Polynomial([ 1., 4., 10., 12., 9.], [-1., 1.], [-1., 1.])
+ Polynomial([ 1., 4., 10., 12., 9.], domain=[-1, 1], window=[-1, 1])
Powers::
>>> p**2
- Polynomial([ 1., 4., 10., 12., 9.], [-1., 1.], [-1., 1.])
+ Polynomial([ 1., 4., 10., 12., 9.], domain=[-1, 1], window=[-1, 1])
Division:
@@ -100,20 +100,20 @@ versions the '/' will only work for division by scalars. At some point it
will be deprecated::
>>> p // P([-1, 1])
- Polynomial([ 5., 3.], [-1., 1.], [-1., 1.])
+ Polynomial([ 5., 3.], domain=[-1, 1], window=[-1, 1])
Remainder::
>>> p % P([-1, 1])
- Polynomial([ 6.], [-1., 1.], [-1., 1.])
+ Polynomial([ 6.], domain=[-1, 1], window=[-1, 1])
Divmod::
>>> quo, rem = divmod(p, P([-1, 1]))
>>> quo
- Polynomial([ 5., 3.], [-1., 1.], [-1., 1.])
+ Polynomial([ 5., 3.], domain=[-1, 1], window=[-1, 1])
>>> rem
- Polynomial([ 6.], [-1., 1.], [-1., 1.])
+ Polynomial([ 6.], domain=[-1, 1], window=[-1, 1])
Evaluation::
@@ -134,7 +134,7 @@ the polynomials are regarded as functions this is composition of
functions::
>>> p(p)
- Polynomial([ 6., 16., 36., 36., 27.], [-1., 1.], [-1., 1.])
+ Polynomial([ 6., 16., 36., 36., 27.], domain=[-1, 1], window=[-1, 1])
Roots::
@@ -148,11 +148,11 @@ tuples, lists, arrays, and scalars are automatically cast in the arithmetic
operations::
>>> p + [1, 2, 3]
- Polynomial([ 2., 4., 6.], [-1., 1.], [-1., 1.])
+ Polynomial([ 2., 4., 6.], domain=[-1, 1], window=[-1, 1])
>>> [1, 2, 3] * p
- Polynomial([ 1., 4., 10., 12., 9.], [-1., 1.], [-1., 1.])
+ Polynomial([ 1., 4., 10., 12., 9.], domain=[-1, 1], window=[-1, 1])
>>> p / 2
- Polynomial([ 0.5, 1. , 1.5], [-1., 1.], [-1., 1.])
+ Polynomial([ 0.5, 1. , 1.5], domain=[-1, 1], window=[-1, 1])
Polynomials that differ in domain, window, or class can't be mixed in
arithmetic::
@@ -180,7 +180,7 @@ conversion of Polynomial classes among themselves is done for type, domain,
and window casting::
>>> p(T([0, 1]))
- Chebyshev([ 2.5, 2. , 1.5], [-1., 1.], [-1., 1.])
+ Chebyshev([ 2.5, 2. , 1.5], domain=[-1, 1], window=[-1, 1])
Which gives the polynomial `p` in Chebyshev form. This works because
:math:`T_1(x) = x` and substituting :math:`x` for :math:`x` doesn't change
@@ -195,18 +195,18 @@ Polynomial instances can be integrated and differentiated.::
>>> from numpy.polynomial import Polynomial as P
>>> p = P([2, 6])
>>> p.integ()
- Polynomial([ 0., 2., 3.], [-1., 1.], [-1., 1.])
+ Polynomial([ 0., 2., 3.], domain=[-1, 1], window=[-1, 1])
>>> p.integ(2)
- Polynomial([ 0., 0., 1., 1.], [-1., 1.], [-1., 1.])
+ Polynomial([ 0., 0., 1., 1.], domain=[-1, 1], window=[-1, 1])
The first example integrates `p` once, the second example integrates it
twice. By default, the lower bound of the integration and the integration
constant are 0, but both can be specified.::
>>> p.integ(lbnd=-1)
- Polynomial([-1., 2., 3.], [-1., 1.], [-1., 1.])
+ Polynomial([-1., 2., 3.], domain=[-1, 1], window=[-1, 1])
>>> p.integ(lbnd=-1, k=1)
- Polynomial([ 0., 2., 3.], [-1., 1.], [-1., 1.])
+ Polynomial([ 0., 2., 3.], domain=[-1, 1], window=[-1, 1])
In the first case the lower bound of the integration is set to -1 and the
integration constant is 0. In the second the constant of integration is set
@@ -215,9 +215,9 @@ number of times the polynomial is differentiated::
>>> p = P([1, 2, 3])
>>> p.deriv(1)
- Polynomial([ 2., 6.], [-1., 1.], [-1., 1.])
+ Polynomial([ 2., 6.], domain=[-1, 1], window=[-1, 1])
>>> p.deriv(2)
- Polynomial([ 6.], [-1., 1.], [-1., 1.])
+ Polynomial([ 6.], domain=[-1, 1], window=[-1, 1])
Other Polynomial Constructors
@@ -233,9 +233,9 @@ are demonstrated below::
>>> from numpy.polynomial import Chebyshev as T
>>> p = P.fromroots([1, 2, 3])
>>> p
- Polynomial([ -6., 11., -6., 1.], [-1., 1.], [-1., 1.])
+ Polynomial([ -6., 11., -6., 1.], domain=[-1, 1], window=[-1, 1])
>>> p.convert(kind=T)
- Chebyshev([ -9. , 11.75, -3. , 0.25], [-1., 1.], [-1., 1.])
+ Chebyshev([ -9. , 11.75, -3. , 0.25], domain=[-1, 1], window=[-1, 1])
The convert method can also convert domain and window::
@@ -249,9 +249,9 @@ available. The cast method works like the convert method while the basis
method returns the basis polynomial of given degree::
>>> P.basis(3)
- Polynomial([ 0., 0., 0., 1.], [-1., 1.], [-1., 1.])
+ Polynomial([ 0., 0., 0., 1.], domain=[-1, 1], window=[-1, 1])
>>> T.cast(p)
- Chebyshev([ -9. , 11.75, -3. , 0.25], [-1., 1.], [-1., 1.])
+ Chebyshev([ -9. , 11.75, -3. , 0.25], domain=[-1, 1], window=[-1, 1])
Conversions between types can be useful, but it is *not* recommended
for routine use. The loss of numerical precision in passing from a
diff --git a/numpy/polynomial/_polybase.py b/numpy/polynomial/_polybase.py
index 96ca20836..78392d2a2 100644
--- a/numpy/polynomial/_polybase.py
+++ b/numpy/polynomial/_polybase.py
@@ -260,7 +260,7 @@ class ABCPolyBase(object):
self.window = window
def __repr__(self):
- format = "%s(%s, %s, %s)"
+ format = "%s(%s, domain=%s, window=%s)"
coef = repr(self.coef)[6:-1]
domain = repr(self.domain)[6:-1]
window = repr(self.window)[6:-1]
diff --git a/numpy/polynomial/chebyshev.py b/numpy/polynomial/chebyshev.py
index dbf380991..b28ea0462 100644
--- a/numpy/polynomial/chebyshev.py
+++ b/numpy/polynomial/chebyshev.py
@@ -361,10 +361,10 @@ def poly2cheb(pol):
>>> from numpy import polynomial as P
>>> p = P.Polynomial(range(4))
>>> p
- Polynomial([ 0., 1., 2., 3.], [-1., 1.])
+ Polynomial([ 0., 1., 2., 3.], domain=[-1, 1], window=[-1, 1])
>>> c = p.convert(kind=P.Chebyshev)
>>> c
- Chebyshev([ 1. , 3.25, 1. , 0.75], [-1., 1.])
+ Chebyshev([ 1. , 3.25, 1. , 0.75], domain=[-1, 1], window=[-1, 1])
>>> P.poly2cheb(range(4))
array([ 1. , 3.25, 1. , 0.75])
diff --git a/numpy/polynomial/legendre.py b/numpy/polynomial/legendre.py
index 5a263ef89..d4b4dd130 100644
--- a/numpy/polynomial/legendre.py
+++ b/numpy/polynomial/legendre.py
@@ -136,10 +136,10 @@ def poly2leg(pol):
>>> from numpy import polynomial as P
>>> p = P.Polynomial(np.arange(4))
>>> p
- Polynomial([ 0., 1., 2., 3.], [-1., 1.])
- >>> c = P.Legendre(P.poly2leg(p.coef))
+ Polynomial([ 0., 1., 2., 3.], domain=[-1, 1], window=[-1, 1])
+ >>> c = P.Legendre(P.legendre.poly2leg(p.coef))
>>> c
- Legendre([ 1. , 3.25, 1. , 0.75], [-1., 1.])
+ Legendre([ 1. , 3.25, 1. , 0.75], domain=[-1, 1], window=[-1, 1])
"""
[pol] = pu.as_series([pol])