python指定概率随机取值参考如下:

下面是利用 np.random.choice()指定概率取样的例子:

np.random.seed(0)
p = np.array([0.1, 0.0, 0.7, 0.2])
index = np.random.choice([0, 1, 2, 3], p = p.ravel())

这意味着你可以以下面的概率分布取到index所对应的数值:
P(index=0)=0.1,P(index=1)=0.0,P(index=2)=0.7,P(index=3)=0.2P(index=0)=0.1,P(index=1)=0.0,P(index=2)=0.7,P(index=3)=0.2.

原文链接:https://blog.csdn.net/qq_33039859/article/details/79939548

 

怎么理解np.random.seed()?

 

 
 

相关文章:

  • 2021-09-12
  • 2022-01-14
  • 2021-11-22
  • 2021-06-10
  • 2022-12-23
  • 2021-08-20
  • 2021-11-27
猜你喜欢
  • 2022-02-08
  • 2022-12-23
  • 2021-07-21
  • 2021-12-01
  • 2021-08-27
  • 2022-01-12
  • 2022-12-23
相关资源
相似解决方案