x_new = torch.zero(x.size()) x_new[x==0] = 1e9 x_new += x _, min_index = torch.min(x_new, dim=1, keepdim=True) min_value = x.gather(1, min_index) # 按照索引位置对原始数据进行索引值

x_new = torch.zero(x.size()) x_new[x==0] = 1e9 x_new += x _, min_index = torch.min(x_new, dim=1, keepdim=True) min_value = x.gather(1, min_index) # 按照索引位置对原始数据进行索引值