It seems that gather cannot make what I need, as the dof tensor, which has the size of batch size X 24, has different indices for each example, but each example has in total 24 indices.
For instance,
dof[0,:] = 0, 1, 6, 9, … (24 in total)
dof[1,:] = 1,100, 151, 300,… (24 in total)
Any hint would be appreciated.