Printing all the contents of a tensor

To avoid truncation and to control how much of the tensor data is printed use the same API as numpy’s numpy.set_printoptions(threshold=10_000).

Example:

x = torch.rand(1000, 2, 2)
print(x) # prints the truncated tensor
torch.set_printoptions(threshold=10_000)
print(x) # prints the whole tensor

If your tensor is very large, adjust the threshold value to a higher number.

Another option is:

torch.set_printoptions(profile="full")
print(x) # prints the whole tensor
torch.set_printoptions(profile="default") # reset
print(x) # prints the truncated tensor

All the available set_printoptions arguments are documented here.

Leave a Comment

tech