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()
1.4m articles
1.4m replys
5 comments
57.0k users