You should use Tensor.select(0, index) or simple slicing syntax tensor[index].
https://pytorch.org/docs/stable/tensors.html#torch.Tensor.select 250
Note that the index must be LongTensor.
def random_indices(self, batch_size=4):
        '''Generate random constellation symbol indices'''
        indices = torch.FloatTensor(batch_size, self.K).uniform_(0, self.constellation_size).long()
        return indices
   
    def modulate(self, indices):
        '''Map indices to constellation symbols'''
        x = self.constellation[indices]
        return x