Skip to content

Instantly share code, notes, and snippets.

@1pha
Created February 23, 2021 12:11
Show Gist options
  • Save 1pha/381341b59b95cad046923566b2d6acf9 to your computer and use it in GitHub Desktop.
Save 1pha/381341b59b95cad046923566b2d6acf9 to your computer and use it in GitHub Desktop.
Discovering how PyTorch takes 'dimension' in many cases, this case max
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