summaryrefslogtreecommitdiff
path: root/numpy/polynomial/polynomial.py
diff options
context:
space:
mode:
authorRoss Barnowski <rossbar@berkeley.edu>2020-02-27 16:30:54 -0800
committerRoss Barnowski <rossbar@berkeley.edu>2020-05-07 10:26:32 -0700
commit9c83b13ce1b08aed8181d284566d002086393a89 (patch)
treee0d8e8316290306ab381e6997399630f0ff1ef01 /numpy/polynomial/polynomial.py
parent965b41d418e6100c1afae0b6f818a7ef152bc25d (diff)
downloadnumpy-9c83b13ce1b08aed8181d284566d002086393a89.tar.gz
ENH: Improved __str__, __format__ for polynomials
Changes the printing style of instances of the convenience classes in the polynomial package to a more "human-readable" format. __str__ has been modified and __format__ added to ABCPolyBase, modifying the string representation of polynomial instances, e.g. when printed. __repr__ and the _repr_latex method (which is used in the Jupyter environment are unchanged. Two print formats have been added: 'unicode' and 'ascii'. 'unicode' is the default mode on *nix systems, and uses unicode values for numeric subscripts and superscripts in the polynomial expression. The 'ascii' format is the default on Windows (due to font considerations) and uses Python-style syntax to represent powers, e.g. x**2. The default printing style can be controlled at the package-level with the set_default_printstyle function. The ABCPolyBase.__str__ has also been made to respect the linewidth printoption. Other parameters from the printoptions dictionary are not used. Co-Authored-By: Warren Weckesser <warren.weckesser@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Diffstat (limited to 'numpy/polynomial/polynomial.py')
-rw-r--r--numpy/polynomial/polynomial.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/numpy/polynomial/polynomial.py b/numpy/polynomial/polynomial.py
index 2fb032db3..97f1e7dc0 100644
--- a/numpy/polynomial/polynomial.py
+++ b/numpy/polynomial/polynomial.py
@@ -1495,6 +1495,14 @@ class Polynomial(ABCPolyBase):
window = np.array(polydomain)
basis_name = None
+ @classmethod
+ def _str_term_unicode(cls, i, arg_str):
+ return f"ยท{arg_str}{i.translate(cls._superscript_mapping)}"
+
+ @staticmethod
+ def _str_term_ascii(i, arg_str):
+ return f" {arg_str}**{i}"
+
@staticmethod
def _repr_latex_term(i, arg_str, needs_parens):
if needs_parens: