torch.randperm — PyTorch 2.7 documentation (original) (raw)

torch.randperm(n, *, generator=None, out=None, dtype=torch.int64, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) → Tensor

Returns a random permutation of integers from 0 to n - 1.

Parameters

n (int) – the upper bound (exclusive)

Keyword Arguments

Example:

torch.randperm(4) tensor([2, 1, 0, 3])