PyTorch torch.randint function
PyTorch torch reference manual
torch.randint is a function in PyTorch used to create a tensor of random integers.
Function definition
torch.randint(low, high, size, dtype, device, requires_grad)
Usage examples
Example
import
torch
Create a tensor of random integers from 0 to 9
x
=
torch.
randint
(
0
,
10
,
(
3
,
4
)
)
(
x
)
The output is:
tensor([[4, 5, 2, 6],
[7, 9, 3, 1],
[2, 8, 5, 4]])