Sorry for bother, I think the right method I need is torch.index_select, like below:
out_reg1 Variable containing:
0.7507  0.2493  0.4223
0.6270  0.9968  0.5263
0.9014  0.5669  0.3850
0.3649  0.1115  0.2633
[torch.FloatTensor of size 4x3]
valid_index = torch.LongTensor([0, 2])
out_reg2 = torch.index_select(out_reg1, 0, Variable(valid_index))
out_reg2 = [
0.7507  0.2493  0.4223,
0.9014  0.5669  0.3850
]
May I ask, do you think this is different from [] ? Is this gonna help me calculate the grad correctly ?
Best
Joe