[numpy]random.choice()随机选取内容
概述:
可以從一個int數(shù)字或1維array里隨機(jī)選取內(nèi)容,并將選取結(jié)果放入n維array中返回。
說明:
numpy.random.choice(a, size=None, replace=True, p=None)
a : 1-D array-like or int 
 If an ndarray, a random sample is generated from its elements. 
 If an int, the random sample is generated as if a was np.arange(n)
size : int or tuple of ints, optional
replace : boolean, optional 
 Whether the sample is with or without replacement
p : 1-D array-like, optional 
 The probabilities associated with each entry in a. If not given the sample assumes a uniform distribution over all entries in a.
示例
>>> np.random.choice(5, 3) array([0, 3, 4])>>> np.random.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0]) array([3, 3, 0])>>> np.random.choice(5, 3, replace=False) array([3,1,0])>>> np.random.choice(5, 3, replace=False, p=[0.1, 0, 0.3, 0.6, 0]) array([2, 3, 0])>>> aa_milne_arr = ['pooh', 'rabbit', 'piglet', 'Christopher']>>> np.random.choice(aa_milne_arr, 5, p=[0.5, 0.1, 0.1, 0.3]) array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'],官方介紹
http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.random.choice.html
總結(jié)
以上是生活随笔為你收集整理的[numpy]random.choice()随机选取内容的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 使用python写一个倒计时_Pytho
- 下一篇: TensorFlow版本
