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 ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值