PyTorch torch.randint_like Function
Pytorch torch Reference Manual
torch.randint_likeIt is a function in PyTorch used to create an integer random tensor with the same shape as the input tensor.
Function Definition
torch.randint_like(input, low=0, high, dtype=None, device=None, requires_grad=False)
Usage Example
Example
import torch
# Create an input tensor
input = torch.tensor([[1, 2], [3, 4]])
# Create an integer random tensor with the same shape as the input, range [0, 10)
x = torch.randint_like(input, 10)
print(x)
# Create an input tensor
input = torch.tensor([[1, 2], [3, 4]])
# Create an integer random tensor with the same shape as the input, range [0, 10)
x = torch.randint_like(input, 10)
print(x)
Other Extensions