numpy.printoptions

numpy.printoptions(*args, **kwargs)[源代码]

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

为的范围设置打印选项 with 块,并在末尾恢复旧选项。见 set_printoptions 有关可用选项的完整描述。

实例

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

这个 as -子句 with -语句提供当前打印选项:

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