How to print the Variable without the info '[torch.FloatTensor of size ]'

I just want to print the value of the loss(Variable type) to the screen
How can I print the Variable without the info ‘[torch.FloatTensor of size ]’

Usually what I do is using the numpy() method to transform the tensor into a numpy object, e.g., print(my_variable.data.cpu().numpy())

2 Likes

I found print(variable.data[0]) could also achieve it

Are you sure of that? That’s not my case @machine

import torch
from torch.autograd import Variable

x = Variable(torch.rand(2,3).float())
print(x.data[0])

outputs:

 0.9121
 0.1402
 0.9595
[torch.FloatTensor of size 3]

I think that’s the case only when x.data[0] is a Tensor of size 1x1.

Btw I edited my other response since there was a bug if you were using the gpu