Hi and thanks @vainaijr. The two methods works well. Do you have an idea of how I can get the values between 2 and 1 as a longtensor. For example in this case, the output would be   x = [torch.LongTensor([3]), torch.LongTensor([7])]? 2 and 1 can be seen as a kind of boundary marker.