KFrank:

t.ge (100.0) * t.le (125.0), -1.0


@KFrank
The script you described set all elements whose values lies in between 100 and 125 to -1.
However, my elements are just some indices and I want the elements who are between specific start and end to be -1.
Just to clarify the confusion let me change the start and end to 41 and 7 respectively.
I want to change x = torch.tensor([1,3,4,41,10,7,5,1,8,3,41,90,78,7,41]) to
torch.tensor([1,3,4,-1,-1,-1,5,1,8,3,-1,-1,-1,-1,41]).
With the code you sent  x.masked_fill_(x.ge(41) * x.le(4), -1.0) the output wouldn’t change.