numpy.printoptions#

numpy.printoptions(*args, **kwargs)[source]#

用于设置打印选项的上下文管理器。

with 块的范围设置打印选项,并在结束时恢复旧选项。有关可用选项的完整说明,请参见 set_printoptions

示例

>>> import numpy as np
>>> from numpy.testing import assert_equal
>>> with np.printoptions(precision=2):
...     np.array([2.0]) / 3
array([0.67])

with 语句的 as 子句提供了当前的打印选项

>>> with np.printoptions(precision=2) as opts:
...      assert_equal(opts, np.get_printoptions())