torch.max / torch.full_like / torch.ones_like / torch.lt / torch.ge

torch.max

a = np.random.rand(5,2)
a = torch.tensor(a)
a_max,a_argmax = torch.max(a, dim=1)

Output:

a : tensor([[0.2805, 0.4071],
             [0.4589, 0.8937],
             [0.5888, 0.5372],
             [0.5745, 0.8074],
             [0.6305, 0.4937]], dtype=torch.float64)
a_max : 
tensor([0.4071, 0.8937, 0.5888, 0.8074, 0.6305], dtype=torch.float64)
a_argmax : 
tensor([1, 1, 0, 1, 0])

torch.full_like(x, 5) : 复制x的size,全部填充5
torch.ones_like(x) : 复制x的size,全部填充1(default)

 x = np.random.rand(2,5)
x = torch.tensor(x)
x_out = torch.full_like(x, 5)

Output:

tensor([[0.3922, 0.7949, 0.8138, 0.7863, 0.4903],
       [0.3115, 0.0753, 0.8717, 0.9812, 0.2786]], dtype=torch.float64)
tensor([[5., 5., 5., 5., 5.],
       [5., 5., 5., 5., 5.]], dtype=torch.float64)

如:IOU_max.shape : [5]
torch.lt(IOU_max, 0.4) = 0 : 得到小于0.4的index shape : [5]
torch.ge(IOU_max, 0.5) = 0 : 得到大于0.5的index shape : [5]

IOU_max = np.random.rand(5)
IOU_max = torch.tensor(IOU_max)
x_out = torch.lt(IOU_max, 0.4)

Output:

tensor([0.3703, 0.2704, 0.6448, 0.7957, 0.3264], dtype=torch.float64)
tensor([ True,  True, False, False,  True])
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值