torch.set_printoptions
- torch.set_printoptions(precision=None, threshold=None, edgeitems=None, linewidth=None, profile=None, sci_mode=None)[源代码]
-
设置打印选项,参考了NumPy的相关内容
- 参数
-
-
precision – 浮点输出的小数位精度,默认值为 4。
-
threshold - 当数组元素的数量超过这个阈值时,会触发汇总操作而非完整显示(默认值为1000)。
-
edgeitems - 每个维度开始和结束位置的数组项目数量(默认为 3)。
-
linewidth - 指定每行的字符数量,用于自动插入换行符,默认值为80。对于阈值化的矩阵,会忽略这个参数。
-
profile - 提供合理的默认设置以美化打印输出。您可以使用上述任一选项来覆盖这些默认设置。(default、short、full中的任意一个)
-
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])