• 文档 >
  • torch >
  • torch.set_printoptions
快捷键

torch.set_printoptions

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

设置打印选项。毫不客气地借鉴了 NumPy

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

  • 阈值 – 触发汇总而不是完整表示的数组元素总数(默认为 1000)。

  • 边界元素 – 每个维度汇总开始和结束处的数组元素数量(默认为 3)。

  • 行宽 – 插入换行符的行字符数(默认为 80)。阈值矩阵将忽略此参数。

  • 配置文件 – 美化打印的默认设置。可以使用上述任何选项进行覆盖。(以下任选其一:默认、简短、完整)

  • 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 贡献者。

使用 Sphinx 构建,并使用 Read the Docs 提供的主题。

文档

PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

查找开发资源并获得您的疑问解答

查看资源