PyTorch: torch.max
- torch.max(input) --> (Tensor)
返回input中的最大值
#torch.max(input) --> (Tensor)
a = torch.rand(1, 3, 5)
>>tensor([[0.4086, 0.7224, 0.5559]])
torch.max(a)
>>tensor(0.7312)
- torch.max(input, dim, keepdim=False, out=None) -> (Tensor, LongTensor)
当dim!=None, 返回在dim维度上的最大值和最大值的索引
a = torch.randn(3, 5)
print(a)
>>tensor([[ 1.2639, 0.9473, 0.3617, -0.1861, 0.1839],
[-0.0825, -0.4322, -0.1637, 1.1394, -0.7880],
[-0.3071, -0.8307, 0.2513, -0.0020, 0.0868]])
max, max_idx = torch.max(a, 1)
print('max={}\n\nmax_idx={}'.format(max, max_idx))
>>max=tensor([1.2639, 1.1394, 0.2513])
max_idx=tensor([0, 3, 2])