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 – 用於美觀列印的合理預設值。可以使用上述任何選項覆蓋。(可以是 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])