e.g. from a torch.rand(4) I would like to obtain a tensor of shape [4, 100, 5]
E.g. torch.rand(4).repeat(100, 5, 1).movedim(-1, 0).contiguous() or torch.rand(4)[..., None, None].expand(4, 100, 5).contiguous() works, but I wonder if there is a more colloquial version?
torch.randn(4, 1, 1).repeat((1, 100, 5))
I’d use the expand and contiguous version if only because repeat used to not be very efficient, so torch.randn(4, 1, 1).expand(-1, 100, 5).contiguous() if you need the contiguous.