I am learning PyTorch and currently working on DCGAN. I am getting my image data along with its age from the dataloader. Now while training the DCGAN I want to give this age values as a condition one-hot vector to make it cDCGAN.
The size of the tensor data1[1] which has age values is batch size=64. following is the python code (step by step ) I am using to get the one-hot vector.
data1[1].size()


# torch.Size([64])

data1[1]

# tensor([18,  6, 20, 65, 41, 18, 15, 63, 17, 16, 45, 21, 62, 19, 13, 32, 41, 24,
    24, 18, 81, 55, 21, 20, 34, 27, 31, 32, 21, 45, 45, 31, 32, 24, 24, 13,
    44, 37, 30, 24,  8, 24, 51, 16, 46, 32, 32, 64, 34, 26, 31, 54, 19, 27,
    17, 31, 16, 21, 27, 29, 30, 35, 24, 20])

samples=data1[1].tolist()

# age categories 
limits = sorted([18, 29, 39, 49, 59, 100])

onehot = []  # this is where we will store our one-hot encodings

for sample in samples:
    row = [0]*len(limits)  # preallocating a list
    for i, limit in enumerate(limits):
          if sample <= limit:
              row[i] = 1
             break

   # storing that sample's onehot into a onehot list of lists
    onehot.append(row)

As you can see I am converting the tensor to list and then converting to the one-hot vector.
My question is it possible  to the same using  torch.nn.functional.one_hot() ?