


vector
tensor([ 2.,  3.,  4.,  5.])
vector.size()
torch.Size([4])
vector[3]                    # indexing into a vector gives a scalar
tensor(5.)
vector[3].item()             # .item() gives the value as a Python number
5.0
mysum = torch.tensor([2, 3]).sum()
mysum
tensor(5)
mysum.size()
torch.Size([])
```



Accumulating losses
Consider the widely used pattern total_loss += loss.data[0]. Before 0.4.0. loss was a Variable wrapping a tensor of size (1,), but in 0.4.0 loss is now a scalar and has 0 dimensions. Indexing into a scalar doesn't make sense (it gives a warning now, but will be a hard error in 0.5.0). Use loss.item() to get the Python number from a scalar.