numpy.printoptions#
- numpy.printoptions(*args, **kwargs)[source]#
用于设置打印选项的上下文管理器。
在 with 块的作用域内设置打印选项,并在结束时恢复旧的选项。有关可用选项的完整描述,请参阅
set_printoptions。备注
这些打印选项仅适用于 NumPy ndarray,不适用于标量。
并发注意事项: 请参阅 文本格式化选项
示例
>>> 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())