一个抽样函数,给定权重(函数自动归一化),抽样一个索引 weights = torch.tensor([1, 2, 3]) index = torch.multinomial(weights, num_samples=1)