Skip to content

Instantly share code, notes, and snippets.

@goddoe
Forked from keon/unsort_pytorch.py
Created September 30, 2018 17:43
Show Gist options
  • Save goddoe/e29cbf8c53bb521e8841c62bf5caa5d1 to your computer and use it in GitHub Desktop.
Save goddoe/e29cbf8c53bb521e8841c62bf5caa5d1 to your computer and use it in GitHub Desktop.
unsort pytorch
x = torch.randn(10)
print(x)
y, ind = torch.sort(x, 0)
print("y", y)
print("ind", ind)
unsorted = y.new(*y.size())
unsorted.scatter_(0, ind, y)
print("unsorted:", unsorted)
print((x - unsorted).abs().max())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment