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 -------- >>> from numpy.testing import assert_equal >>
(*args, **kwargs)
| 334 | @set_module('numpy') |
| 335 | @contextlib.contextmanager |
| 336 | def printoptions(*args, **kwargs): |
| 337 | """Context manager for setting print options. |
| 338 | |
| 339 | Set print options for the scope of the `with` block, and restore the old |
| 340 | options at the end. See `set_printoptions` for the full description of |
| 341 | available options. |
| 342 | |
| 343 | Examples |
| 344 | -------- |
| 345 | |
| 346 | >>> from numpy.testing import assert_equal |
| 347 | >>> with np.printoptions(precision=2): |
| 348 | ... np.array([2.0]) / 3 |
| 349 | array([0.67]) |
| 350 | |
| 351 | The `as`-clause of the `with`-statement gives the current print options: |
| 352 | |
| 353 | >>> with np.printoptions(precision=2) as opts: |
| 354 | ... assert_equal(opts, np.get_printoptions()) |
| 355 | |
| 356 | See Also |
| 357 | -------- |
| 358 | set_printoptions, get_printoptions |
| 359 | |
| 360 | """ |
| 361 | opts = np.get_printoptions() |
| 362 | try: |
| 363 | np.set_printoptions(*args, **kwargs) |
| 364 | yield np.get_printoptions() |
| 365 | finally: |
| 366 | np.set_printoptions(**opts) |
| 367 | |
| 368 | |
| 369 | def _leading_trailing(a, edgeitems, index=()): |
no outgoing calls