pytorch best way to call unique_consecutive() on certain dimension of a tensor?

Viewed 297

What's the best way to call unique_consecutive() on certain dimension of a tensor, and pad the left-out with specified values? For simplicity, we could use 2D tensor as an example:

input = tensor([[3, 3, 5, 5, 5],
                [3, 3, 2, 2, 3]])

if specifying padding value -1, what i hope to get is:

output = tensor([[3, 5, -1, -1, -1],
                 [3, 2, 3, -1, -1]])

Also, to save memory, i'd prefer to do so in-place if possible. Thanks!

1 Answers
Related