You can use scatter 964 for this purpose.
For example:
# your tensor of 16 x 28 dimensions, 
# where each element has some index (0 to n)
inp = torch.LongTensor(16, 28) % n    
inp_ = torch.unsqueeze(inp, 2)

one_hot = torch.FloatTensor(16, 28, n).zero_()
one_hot.scatter_(2, inp_, 1)

print(inp)
print(one_hot)