Tile/repeat different number of times

Hello. How can I tile/repeat a tensor in such a way that each value is tiled/repeated a different number of times other than looping then concatenating?
For e.g., from torch.Tensor([0, 1]), how can I tile the first value two times and the second three times to get torch.Tensor([0, 0, 1, 1, 1]). Thanks in advance!

torch.repeat_interleave should work:

x = torch.tensor([0, 1])
print(torch.repeat_interleave(x, torch.tensor([2, 3])))
> tensor([0, 0, 1, 1, 1])
1 Like

Awesome thanks. I thought torch.repeat_interleave worked for only integers.

1 Like