快捷方式

torch.set_printoptions

torch.set_printoptions(precision=None, threshold=None, edgeitems=None, linewidth=None, profile=None, sci_mode=None)[源][源]

设置打印选项。这些选项借鉴自 NumPy

参数
  • precision – 浮点输出的精度位数(默认为 4)。

  • threshold – 数组元素总数。当元素总数超过此阈值时,会触发摘要显示而非完整 repr (默认为 1000)。

  • edgeitems – 在每个维度摘要开头和结尾显示的数组元素数量(默认为 3)。

  • linewidth – 用于插入换行符的每行字符数(默认为 80)。超出阈值的矩阵将忽略此参数。

  • profile – 美观打印的合理默认设置。可以通过上述任何选项覆盖。(可以是 defaultshortfull 中的一个)

  • sci_mode – 启用(True)或禁用(False)科学记数法。如果指定为 None(默认值),则该值由 torch._tensor_str._Formatter 定义。框架会自动选择此值。

示例

>>> # Limit the precision of elements
>>> torch.set_printoptions(precision=2)
>>> torch.tensor([1.12345])
tensor([1.12])
>>> # Limit the number of elements shown
>>> torch.set_printoptions(threshold=5)
>>> torch.arange(10)
tensor([0, 1, 2, ..., 7, 8, 9])
>>> # Restore defaults
>>> torch.set_printoptions(profile='default')
>>> torch.tensor([1.12345])
tensor([1.1235])
>>> torch.arange(10)
tensor([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

文档

查阅 PyTorch 全面的开发者文档

查阅文档

教程

获取针对初学者和高级开发者的深入教程

查阅教程

资源

查找开发资源并获得问题解答

查阅资源