Get subset of tensor with different number of columns


I am trying to extract from a tensor a subset without using a loop. But each row of the subset will not necesseraly have the same number of columns. I was wondering if it is possible without a loop. (threfore I need to get a list at the end)
Let’s say I have a tensor of size (5,10). I want to extract the element :

  • row 0 : columns [2:6]
  • row 1 : columns [2:8]
  • row 2 : columns [2:9]
  • row 3 : columns [1:3]
  • row 4 : columns [0:6]

With a loop it is easy

T = .. # tensor
begin = [2,2,2,1,0]
end = [6,8,9,3,6]
for i, x in enumerate(T):
       res.append(x[begin[i]: end[i]])


Given that the result is a list. Then you won’t be able to use an efficient Tensor function to do this I’m afraid.