I figured out a (not elegant) solution:
t = torch.rand(50, 2, 20, 20, ...)  # suppose to have n + 2 dimensions
ids = torch.meshgrid(*[torch.arange(10) for _ in range(n)])
ids = (slice(None),) * 2 + ids 
print(t[ids])