print('1111',loss)
print('2222',loss.data)#tensor且GPU
print('3333',loss.cpu())
print('4444',loss.cpu().data)#tensor且CPU
# print('5555',loss.cpu().data[0])#报错 IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
# print('6666',loss.cpu().numpy())#报错 RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.
print('7777',loss.cpu().detach().numpy())
print('8888',loss.cpu().data.numpy())
print('9999',loss.cpu().item())
print('aaaa',loss.item())#后四者一样,都是把数值取出来
结果: