How to slice multiple interval over tensor

Hi, is there any method to do the same thing with the code below without loop:

tensors have the dimension [B, C, T, H, W]
I want to slice the tensor in T axis with multiple start, end pair

   for b in range(B):
        for h in range(H):
            for w in range(W):
                interval = torch.arange(starts[b][h][w],ends[b][h][w])
                cropped[b,:,:,h,w] = origin[b, :, interval, h,w]
1 Like