先看一下定义(没上官网,在外,热点官网上不去)
def multinomial(self: Tensor, num_samples: _int, replacement: _bool=False, *, generator: Generator=None, out: Optional[Tensor]=None) -> Tensor: ...
参数:
实验
import torch
# import numpy as np
freq = torch.Tensor([0.1,0.2,0.3,0.9])
K = 2
# generate = torch.Generator
res = torch.multinomial(input = freq,num_samples=K,replacement=True)
print(res)
结果
基本上每次都是:
tensor([3, 3])
但也有别的情况