Why the output of torch.rand() keeps only four decimal places

This is just how the tensors are displayed. If you print(a.item()), you should see more figures. You can force the data type in torch.rand(), too, with the keyword argument dtype = torch.<your desired datatype, eg. float64> which can allow for even more significant figures, if you’d like.

Check out this topic if you want to always print your tensors with more figures after the decimal shown.