Skip to content

Instantly share code, notes, and snippets.

@vaibkumr
Last active October 11, 2019 18:23
Show Gist options
  • Save vaibkumr/2292ac3ef7196fd5b2138846e0c943dd to your computer and use it in GitHub Desktop.
Save vaibkumr/2292ac3ef7196fd5b2138846e0c943dd to your computer and use it in GitHub Desktop.
#####################
# Before PyTorch v1.3
#####################
import torch
batch = torch.zeros(2, 3, 2, 2, 2, 2, 2, 2, 2, 2)
print(batch.shape)
batch = batch.permute([0, 2, 1, 3, 4, 5, 6, 7, 8, 9])
print(batch.shape)
#####################
# After PyTorch v1.3
#####################
import torch
alphas = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
batch = torch.zeros(2, 3, 2, 2, 2, 2, 2, 2, 2, 2, names=alphas)
print(batch.shape)
batch = batch.align_to('a', 'c', 'b', ...)
print(batch.shape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment