torch.Tensor.new_tensor
- Tensor.new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory
Returns a new Tensor with data as the tensor data.
By default, the returned Tensor has the same torch.dtype and
torch.device as this tensor.
data (array_like) – The returned Tensor copies data.
dtype (torch.dtype, optional) – the desired type of returned tensor.
Default: if None, same torch.dtype as this tensor.
device (torch.device, optional) – the desired device of returned tensor.
Default: if None, same as this tensor.
Example:
>>> tensor = torch.ones((2,), dtype=torch.int8)
>>> data = [[0, 1], [2, 3]]
>>> tensor.new_tensor(data)
tensor([[ 0, 1],
torch.devicerequires_grad (bool, optional) – If autograd should record operations on the
returned tensor. Default: False.
layout (torch.layout, optional) – the desired layout of returned Tensor.
Default: torch.strided.
pin_memory (bool, optional) – If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: False.