Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.randint function

PyTorch torch.randint function


PyTorch torch reference manual 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

)

)

print

(

x

)

The output is:

tensor([[4, 5, 2, 6],

        [7, 9, 3, 1],

        [2, 8, 5, 4]])


PyTorch torch reference manual PyTorch torch reference manual