首页 > 学院 > 开发设计 > 正文

np.random.choice

2019-11-06 08:23:55
字体:
来源:转载
供稿:网友
>>> N =21>>> indices = np.random.choice(N, 1, replace=False)>>> indicesarray([5])>>> indices = np.random.choice(N, 1, replace=False)>>> indicesarray([17])>>> indices = np.random.choice(N)>>> indices7

第一个参数表示从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'],


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表