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])