torch.set_printoptions
function set_printoptions(options: PrintOptions = {}): voidConfigures how tensors are displayed when printed or logged.
These options control the formatting of tensor string representations. Useful for adjusting output verbosity, precision, and readability when debugging or analyzing tensor values.
Common Use Cases:
- Debugging: Increase precision to see more decimal places
- Performance analysis: Use 'short' profile for compact output
- Tensor inspection: Use 'full' profile to see all elements
- Logging: Adjust threshold to control tensor summarization
Profiles:
- 'default': Balanced precision (4), shows first/last 3 elements
- 'short': Compact output with precision 2, threshold 100
- 'full': Complete output with precision 8, no summarization
- Partial updates: Only specified options are changed
- Profile overrides: Setting profile applies default values for that profile
- Global setting: Affects all subsequent tensor printing
- Display-only: Doesn't affect internal tensor representation
Parameters
optionsPrintOptionsoptional- Partial options object with any fields to update
Returns
void
Examples
// Show more decimal places for debugging
torch.set_printoptions({ precision: 8 });
console.log(x); // 8 decimal places
// Compact output for large tensors
torch.set_printoptions({ profile: 'short' });
const big = torch.randn(1000, 1000);
console.log(big); // Summarized output
// Full output for small tensors
torch.set_printoptions({ profile: 'full' });
const small = torch.arange(10);
console.log(small); // All 10 elements shown
// Custom settings
torch.set_printoptions({
precision: 3,
threshold: 50, // Summarize tensors with > 50 elements
edgeitems: 2, // Show first/last 2 elements
linewidth: 120, // Lines up to 120 characters
sci_mode: true // Use scientific notation
});See Also
- PyTorch torch.set_printoptions()
- get_printoptions - Query current print settings