PyTorch: new_ones vs ones
In PyTorch what is the difference between new_ones() vs ones(). For example,

x2.new_ones(3,2, dtype=torch.double)


vs 

torch.ones(3,2, dtype=torch.double)


For the sake of this answer, I am assuming that your x2 is a previously defined torch.Tensor. If we then head over to the PyTorch documentation, we can read the following on new_ones():


  Returns a Tensor of size size filled with 1. By default, the
  returned Tensor has the same torch.dtype and torch.device as this
  tensor.


Whereas ones()


  Returns a tensor filled with the scalar value 1, with the shape
  defined by the variable argument sizes.


So, essentially, new_ones allows you to quickly create a new torch.Tensor on the same device and data type as a previously existing tensor (with ones), whereas ones() serves the purpose of creating a torch.Tensor from scratch (filled with ones).
