CHH3213 / Note-Ubuntu_CHH3213

ubuntu系统CHH3213上做的笔记
0 stars 0 forks source link

68. torch.max() #68

Open CHH3213 opened 2 years ago

CHH3213 commented 2 years ago

形式:torch.max(input) → Tensor

返回输入tensor中所有元素的最大值:

a = torch.randn(1, 3)
>>0.4729 -0.2266 -0.2085
torch.max(a) #也可以写成a.max()
>>0.4729

形式: torch.max(input, dim, keepdim=False, out=None) -> (Tensor, LongTensor)

按维度dim 返回最大值,并且返回索引。

示例

a = torch.tensor([[3, 5], [2, 3], [6, 7]])
b = torch.max(a, 0)[0]
c = torch.max(a, 1)[0]
print('a:',a)
print('b:',b)
print('c:',c)

输出为

a: tensor([[3, 5],
        [2, 3],
        [6, 7]])
b: tensor([6, 7])
c: tensor([5, 3, 7])