Efficient way to get ordered permuations

I have integer numbers in ascending order from 1 to n with a difference of 1 like this :1,2,3,4,…, n . I want to get ordered permutation of the desired length of m. for example if n is 3 and m is 2 then the output should be (1,2),(2,3),(1,3).

I guess you could use itertools.permutations to permute your list.
PS: this doesn’t seem to be PyTorch-specific, so note that you might get a faster and better answer e.g. on StackOverflow. :wink:

1 Like