PyTorch torch.rand_like Function
PyTorch torch Reference Manual
torch.rand_likeis a function in PyTorch used to create a uniformly distributed random tensor with the same shape as the input tensor.
Function Definition
torch.rand_like(input, dtype=None, device=None, requires_grad=False)
Usage Examples
Example
import torch
# Create an input tensor
input = torch.tensor([[1, 2], [3, 4]])
# Create a uniformly distributed random tensor with the same shape as the input [0, 1)
x = torch.rand_like(input)
print(x)
# Create an input tensor
input = torch.tensor([[1, 2], [3, 4]])
# Create a uniformly distributed random tensor with the same shape as the input [0, 1)
x = torch.rand_like(input)
print(x)
Other Extensions