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