Created
January 4, 2018 09:02
-
-
Save keon/167fc97441f9f332895afc3bcc33ffd8 to your computer and use it in GitHub Desktop.
unsort pytorch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
0.5140
1.8583
1.2117
-0.8053
-0.5985
-0.9133
-0.0411
-0.8822
0.2321
-0.3467
[torch.FloatTensor of size 10]
y
-0.9133
-0.8822
-0.8053
-0.5985
-0.3467
-0.0411
0.2321
0.5140
1.2117
1.8583
[torch.FloatTensor of size 10]
ind
5
7
3
4
9
6
8
0
2
1
[torch.LongTensor of size 10]
unsorted:
0.5140
1.8583
1.2117
-0.8053
-0.5985
-0.9133
-0.0411
-0.8822
0.2321
-0.3467
[torch.FloatTensor of size 10]
0.0