torch.max(input, dim, keepdim=False, out=None) -> (Tensor, LongTensor)
max函数需要注意的是,它是一个过载函数,函数参数不同函数的功能和返回值也不同。
当max函数中有维数参数的时候,它的返回值为两个,一个为最大值,另一个为最大值的索引
a = torch.randn(4, 4)
a
0.0692 0.3142 1.2513 -0.5428
0.9288 0.8552 -0.2073 0.6409
1.0695 -0.0101 -2.4507 -1.2230
0.7426 -0.7666 0.4862 -0.6628
torch.FloatTensor of size 4x4]
torch.max(a, 1)
(
1.2513
0.9288
1.0695
0.7426
[torch.FloatTensor of size 4]
,
2
0
0
0
[torch.LongTensor of size 4]
)