How to split a tensor by segments

Hello,

I have an output tensor for which the shape is (3,5,100). So, for my case 16 is the batch size, 64 is the number of steps, and 100 is the features for each step.
Moreover, I have the following information:
[[1,0,0,1,0] , [1,1,0,1,1], [1,0,0,0,1]]

So, [1,0,0,1,0] means that for the 1st tensor in my batch I want to split that tensor from index 0 to index 2 and from index 3 to index 5 (the end of the sequence).

[1,1,0,1,1] means that for the 2nd tensor in my batch I want to split that tensor from index 0 to index 0 and from index 1 to index 2 and from index 3 to index 3 and from index 4 to index 4.

So, in this batch, I will result with some segments of tensors that I will apply the mean on.

What’s the most efficient way to do it?