母列为data,子列序数为index
SIZE = 16
data = torch.rand((SIZE,))
index = torch.randint(0,SIZE,(SIZE,))>=(SIZE//2)
print(data)
print(index)
print('子列:',data[index])
print('补集:',data[~index])
tensor([0.2880, 0.9067, 0.7970, 0.0185, 0.8694, 0.0878, 0.4772, 0.6175, 0.1135,
0.8980, 0.5136, 0.4684, 0.6399, 0.5803, 0.6921, 0.6084])
tensor([ True, True, True, False, False, True, True, True, False, True,
False, True, False, False, False, False])
子列: tensor([0.2880, 0.9067, 0.7970, 0.0878, 0.4772, 0.6175, 0.8980, 0.4684])
补集: tensor([0.0185, 0.8694, 0.1135, 0.5136, 0.6399, 0.5803, 0.6921, 0.6084])