MCPcopy Create free account
hub / github.com/numpy/numpy / printoptions

Function printoptions

numpy/core/arrayprint.py:336–366  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

334@set_module('numpy')
335@contextlib.contextmanager
336def 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
369def _leading_trailing(a, edgeitems, index=()):

Callers 6

test_strMethod · 0.90
test_latexMethod · 0.90
test_fixedMethod · 0.90
test_switch_to_expMethod · 0.90
test_non_finiteMethod · 0.90

Calls

no outgoing calls

Tested by 6

test_strMethod · 0.72
test_latexMethod · 0.72
test_fixedMethod · 0.72
test_switch_to_expMethod · 0.72
test_non_finiteMethod · 0.72