torch.max的用法

x = torch.rand(4,4)
print('x:\n',x)
print('torch.max(x,1):\n',torch.max(x,1))
print('torch.max(x,0):\n',torch.max(x,0))
print('torch.max(x,1)[0]:\n',torch.max(x,1)[0])
print('torch.max(x,1)[1]:\n',torch.max(x,1)[1])
print('torch.max(x,1)[1].data:\n',torch.max(x,1)[1].data)
print('torch.max(x,1)[1].data.numpy():\n',torch.max(x,1)[1].data.numpy())
print('torch.max(x,1)[1].data.numpy().squeeze():\n',torch.max(x,1)[1].data.numpy().squeeze())
print('torch.max(x,1)[0].data:\n',torch.max(x,1)[0].data)
print('torch.max(x,1)[0].data.numpy():\n',torch.max(x,1)[0].data.numpy())
print('torch.max(x,1)[0].data.numpy().squeeze():\n',torch.max(x,1)[0].data.numpy().squeeze())`
x:
 tensor([[0.5285, 0.1247, 0.8332, 0.5485],
        [0.7917, 0.6138, 0.5881, 0.3381],
        [0.4226, 0.6605, 0.8571, 0.0399],
        [0.1716, 0.0609, 0.9712, 0.4838]])
        
torch.max(x,1):
 (tensor([0.8332, 0.7917, 0.8571, 0.9712]), tensor([2, 0, 2, 2]))
 
torch.max(x,0):
 (tensor([0.7917, 0.6605, 0.9712, 0.5485]), tensor([1, 2, 3, 0]))
 
torch.max(x,1)[0]:
 tensor([0.8332, 0.7917, 0.8571, 0.9712])
 
torch.max(x,1)[1]:
 tensor([2, 0, 2, 2])
 
torch.max(x,1)[1].data:
 tensor([2, 0, 2, 2])
 
torch.max(x,1)[1].data.numpy():
 [2 0 2 2]
 
torch.max(x,1)[1].data.numpy().squeeze():
 [2 0 2 2]
 
torch.max(x,1)[0].data:
 tensor([0.8332, 0.7917, 0.8571, 0.9712])
 
torch.max(x,1)[0].data.numpy():
 [0.83318216 0.7917127  0.85708565 0.9711726 ]
 
torch.max(x,1)[0].data.numpy().squeeze():
 [0.83318216 0.7917127  0.85708565 0.9711726 ]
发布了21 篇原创文章 · 获赞 3 · 访问量 191

猜你喜欢

转载自blog.csdn.net/qq_38799933/article/details/105450596