Skip to content

Instantly share code, notes, and snippets.

@Hanrui-Wang
Created August 13, 2019 19:32
Show Gist options
  • Save Hanrui-Wang/5fa21b829c622e06d760dfc2012e9d13 to your computer and use it in GitHub Desktop.
Save Hanrui-Wang/5fa21b829c622e06d760dfc2012e9d13 to your computer and use it in GitHub Desktop.
convert a digits to one hot
print(labels.detach().numpy())
labels.unsqueeze_(-1)
print(labels.detach().numpy())
labels_onehot = torch.FloatTensor(batch_size, 10)
labels_onehot.zero_()
labels_onehot.scatter_(1, labels, 1)
print(labels_onehot.detach().numpy())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment