diff options
author | Eugene Prilepin <esp.home@gmail.com> | 2019-10-06 08:17:47 +0300 |
---|---|---|
committer | Matti Picus <matti.picus@gmail.com> | 2019-10-06 08:17:47 +0300 |
commit | b0ecf775f31332bf1612a2f884d61935a605bce6 (patch) | |
tree | 612b9d0d46b447668fa8e1e0bc53a5757853f718 | |
parent | 49e00940a82f9590d774539cd188b634c29fc39f (diff) | |
download | numpy-b0ecf775f31332bf1612a2f884d61935a605bce6.tar.gz |
DOC: add `printoptions` as a context manager to `set_printoptions` (#14636)
DOC: add `printoptions` as a context manager to `set_printoptions`
-rw-r--r-- | numpy/core/arrayprint.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index b1310a737..233d139fd 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -200,6 +200,8 @@ def set_printoptions(precision=None, threshold=None, edgeitems=None, ----- `formatter` is always reset with a call to `set_printoptions`. + Use `printoptions` as a context manager to set the values temporarily. + Examples -------- Floating point precision can be set: @@ -236,9 +238,16 @@ def set_printoptions(precision=None, threshold=None, edgeitems=None, To put back the default options, you can use: - >>> np.set_printoptions(edgeitems=3,infstr='inf', + >>> np.set_printoptions(edgeitems=3, infstr='inf', ... linewidth=75, nanstr='nan', precision=8, ... suppress=False, threshold=1000, formatter=None) + + Also to temporarily override options, use `printoptions` as a context manager: + + >>> with np.printoptions(precision=2, suppress=True, threshold=5): + ... np.linspace(0, 10, 10) + array([ 0. , 1.11, 2.22, ..., 7.78, 8.89, 10. ]) + """ legacy = kwarg.pop('legacy', None) if kwarg: |