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

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

Returns a tensor with the same size as input that is filled with random numbers from a uniform distribution on the interval [0,1)[0, 1).torch.rand_like(input) is equivalent totorch.rand(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