Hi Mohit,
This is the expected behavior. Actually the second argument is the index along which you want to find the max. So, performing torch.max(a, n) finds the maximum values of a along n-th dimension and returns the corresponding value and it's index.
Whereas simply performing torch.max(a), without specifying any index, simply returns the maximum value in the entire tensor. It does not return any index since it does not know along which dimension to return the value.
Say, I define a tensor
a = torch.randn(4, 4)
th> a
-0.6962 0.0353 0.5913 1.0324
1.6723 -1.4893 0.1162 0.2568
-0.6003 -0.0142 -0.9288 -0.4990
2.0170 -1.3219 0.2130 -0.4947
Now if I perform
val, idx = torch.max(a, 2)
th> val
1.0324
1.6723
-0.0142
2.0170
[torch.DoubleTensor of size 4x1]
th> idx
4
1
2
1
[torch.LongTensor of size 4x1]
It returns things as expected. But if I simply do torch.max(a) it will simply return the max value as shown below.
torch.max(a)
2.0169710614992
It is just a number, not associated with any index. The reason for this is it does not know along which dimension to index. Will it be along the row (which is 4) or column (which is 1) or both row and column (4 X 2). Things will get even more complicated for higher dimension.
Hence such a behavior.