Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@killeent
Created June 26, 2017 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killeent/ea0f726302fc228580c56cf27b4abba6 to your computer and use it in GitHub Desktop.
Save killeent/ea0f726302fc228580c56cf27b4abba6 to your computer and use it in GitHub Desktop.
In [1]: import torch
In [2]: x = torch.arange(0, 64).view(8, 8)
In [3]: x
Out[3]:
0 1 2 3 4 5 6 7
8 9 10 11 12 13 14 15
16 17 18 19 20 21 22 23
24 25 26 27 28 29 30 31
32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47
48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63
[torch.FloatTensor of size 8x8]
In [4]: x[:, [3, 4]]
Out[4]:
3 4
11 12
19 20
27 28
35 36
43 44
51 52
59 60
[torch.FloatTensor of size 8x2]
In [5]: x[[1, 1], :]
Out[5]:
8 9 10 11 12 13 14 15
8 9 10 11 12 13 14 15
[torch.FloatTensor of size 2x8]
In [6]: x = x.view(4, 4, 4)
In [7]: x
Out[7]:
(0 ,.,.) =
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
(1 ,.,.) =
16 17 18 19
20 21 22 23
24 25 26 27
28 29 30 31
(2 ,.,.) =
32 33 34 35
36 37 38 39
40 41 42 43
44 45 46 47
(3 ,.,.) =
48 49 50 51
52 53 54 55
56 57 58 59
60 61 62 63
[torch.FloatTensor of size 4x4x4]
In [8]: x[:, [3, 2, 1], :]
Out[8]:
(0 ,.,.) =
12 13 14 15
8 9 10 11
4 5 6 7
(1 ,.,.) =
28 29 30 31
24 25 26 27
20 21 22 23
(2 ,.,.) =
44 45 46 47
40 41 42 43
36 37 38 39
(3 ,.,.) =
60 61 62 63
56 57 58 59
52 53 54 55
[torch.FloatTensor of size 4x3x4]
In [9]: x[[0, 1], [0], :]
Out[9]:
0 1 2 3
16 17 18 19
[torch.FloatTensor of size 2x4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment