Created
February 23, 2021 12:11
-
-
Save 1pha/381341b59b95cad046923566b2d6acf9 to your computer and use it in GitHub Desktop.
Discovering how PyTorch takes 'dimension' in many cases, this case max
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
import torch | |
sample_tensor = torch.Tensor([ | |
[1, 2, 3, 4, 5, 6], | |
[7, 8, 9, 10, 11, 12], | |
[13, 14, 15, 16, 17, 18], | |
]) | |
sample_tensor = sample_tensor.view(3, 6//2, -1) | |
#tensor([[[ 1., 2.], | |
# [ 3., 4.], | |
# [ 5., 6.]], | |
# | |
# [[ 7., 8.], | |
# [ 9., 10.], | |
# [11., 12.]], | |
# | |
# [[13., 14.], | |
# [15., 16.], | |
# [17., 18.]]]) | |
print(sample_tensor.max().values) | |
print(sample_tensor.max(0).values) | |
print(sample_tensor.max(1).values) | |
print(sample_tensor.max(2).values) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment