Printing the tensor gives:
>>> x = torch.tensor([3]) >>> print(x) tensor([3])
Likewise indexing its .data gives:
.data
>>> x.data[0] tensor(3)
How do I get just the value 3?
3
You can use x.item() to get a Python number from a tensor that has one element.
x.item()
2.1m questions
2.1m answers
60 comments
57.0k users