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

PyTorch torch.randint_like function

PyTorch torch.randint_like function


PyTorch torch reference manual PyTorch torch reference manual

torch.randint_like is a function in PyTorch used to create a tensor of random integers 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 examples

Example

import

torch

Create an input tensor

input

=

torch.

tensor

(

[

[

1

,

2

]

,

[

3

,

4

]

]

)

Create a tensor of random integers with the same shape as the input, in the range [0, 10)

x

=

torch.

randint_like

(

input

,

10

)

print

(

x

)


PyTorch torch reference manual PyTorch torch reference manual