Torch.repeat_interleave on dictionary?

Hi everyone! I need to repeat an object ( in type dictionary). Wanna use the torch.repeat_interleave function. What’s the best way of doing so? Shall I convert the dictionary or list to tensor first?

Thank you!

Yes, torch.repeat_interleave expects a tensor as its input.

Thank you! Is there a function that directly do so, or do I need to write a for-loop for the conversion?

If you’ve created a list containing tensors with the same shape you could use e.g. torch.stack or

l = [torch.randn(10, 10) for _ in range(3)]

x = torch.stack(l)
# > torch.Size([3, 10, 10])

y =
# > torch.Size([30, 10])

For more advanced use cases it would depend on the actual use case.

Thank you very much!