PyTorch torch.randint Function
Pytorch torch Reference Manual
torch.randintIt is a function in PyTorch used to create random integer tensors.
Function Definition
torch.randint(low, high, size, dtype, device, requires_grad)
Usage Examples
Example
import torch
# Create a random integer tensor from 0 to 9
x = torch.randint(0, 10, (3, 4))
print(x)
# Create a random integer tensor from 0 to 9
x = torch.randint(0, 10, (3, 4))
print(x)
The output result is:
tensor([[4, 5, 2, 6],
[7, 9, 3, 1],
[2, 8, 5, 4]])
Other Extensions