Search code examples
pytorch

Pytorch beginner : tensor.new method


everyone, I have a small question.

What is the purpose of the method tensor.new(..) in Pytorch, I didn't find anything in the documentation. It looks like it creates a new Tensor (like the name suggests), but why we don't just use torch.Tensor constructors instead of using this new method that requires an existing tensor.

Thank you in advance.


Solution

  • As the documentation of tensor.new() says:

    Constructs a new tensor of the same data type as self tensor.

    Also note:

    For CUDA tensors, this method will create new tensor on the same device as this tensor.