Context manager for setting print options. Set print options for the scope of the `with` block, and restore the old options at the end. See `set_printoptions` for the full description of available options. Examples -------- >>> import numpy as np >>> from numpy.testing
(*args, **kwargs)
| 396 | @set_module('numpy') |
| 397 | @contextlib.contextmanager |
| 398 | def printoptions(*args, **kwargs): |
| 399 | """Context manager for setting print options. |
| 400 | |
| 401 | Set print options for the scope of the `with` block, and restore the old |
| 402 | options at the end. See `set_printoptions` for the full description of |
| 403 | available options. |
| 404 | |
| 405 | Examples |
| 406 | -------- |
| 407 | >>> import numpy as np |
| 408 | |
| 409 | >>> from numpy.testing import assert_equal |
| 410 | >>> with np.printoptions(precision=2): |
| 411 | ... np.array([2.0]) / 3 |
| 412 | array([0.67]) |
| 413 | |
| 414 | The `as`-clause of the `with`-statement gives the current print options: |
| 415 | |
| 416 | >>> with np.printoptions(precision=2) as opts: |
| 417 | ... assert_equal(opts, np.get_printoptions()) |
| 418 | |
| 419 | See Also |
| 420 | -------- |
| 421 | set_printoptions, get_printoptions |
| 422 | |
| 423 | Notes |
| 424 | ----- |
| 425 | These print options apply only to NumPy ndarrays, not to scalars. |
| 426 | |
| 427 | **Concurrency note:** see :ref:`text_formatting_options` |
| 428 | |
| 429 | """ |
| 430 | token = _set_printoptions(*args, **kwargs) |
| 431 | |
| 432 | try: |
| 433 | yield get_printoptions() |
| 434 | finally: |
| 435 | format_options.reset(token) |
| 436 | |
| 437 | |
| 438 | def _leading_trailing(a, edgeitems, index=()): |
searching dependent graphs…