美文网首页
torch.distributions.Categorical

torch.distributions.Categorical

作者: 何哀何欢 | 来源:发表于2020-07-21 15:28 被阅读0次

从一个样本空间中,抽样。
比如:
我要抽 [0, 1, 2] 三个物体,共100次,那我希望:

  • 0能抽到20次左右
  • 1能抽到70次左右
  • 2能抽到30次左右
x = torch.Tensor([2, 7, 3]) #20次,70次,30次
m = torch.distributions.Categorical(x)
re = [0, 0, 0] #三个数抽到的个数
for i in range(100):
    re[m.sample()] += 1 #sample就是抽一次

plt.bar([0, 1, 2], re)

相关文章

  • torch.distributions.Categorical

    从一个样本空间中,抽样。比如:我要抽 [0, 1, 2] 三个物体,共100次,那我希望: 0能抽到20次左右 1...

网友评论

      本文标题:torch.distributions.Categorical

      本文链接:https://www.haomeiwen.com/subject/pkbikktx.html