torch.empty_like — PyTorch 2.7 documentation (original) (raw)

torch.empty_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) → Tensor

Returns an uninitialized tensor with the same size as input.torch.empty_like(input) is equivalent totorch.empty(input.size(), dtype=input.dtype, layout=input.layout, device=input.device).

Parameters

input (Tensor) – the size of input will determine size of the output tensor.

Keyword Arguments

Example:

a=torch.empty((2,3), dtype=torch.int32, device = 'cuda') torch.empty_like(a) tensor([[0, 0, 0], [0, 0, 0]], device='cuda:0', dtype=torch.int32)