您的位置:首页 > 其它

np.random.choice

2017-03-02 16:54 204 查看
>>> N =21
>>> indices = np.random.choice(N, 1, replace=False)
>>> indices
array([5])
>>> indices = np.random.choice(N, 1, replace=False)
>>> indices
array([17])
>>> indices = np.random.choice(N)
>>> indices
7


第一个参数表示从N中选择,第二个参数表示选几个default是1个返回数字,,replace具体用途还不知道,p表示概率

>>> 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'],
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: