python指定概率隨機取值 理解np.random.seed()


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()?

 

 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM