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'],
相关文章推荐
- np.random.choice的用法
- np.random.choice 参数replace
- [numpy]random.choice()随机选取内容
- numpy 随机数种类np.random.RandomState、np.random.rand、np.random.random、np.random_sample
- Python random模块sample、randint、shuffle、choice随机函数
- np.random.RandomState
- 二项分布的实现(np.random.binomial)
- np.random.seed(0)的作用:作用:使得随机数据可预测
- np.random 的使用
- np.random.random 使用法
- python中的np.random.normal
- np.random.
- numpy: np.random模块 探究(源码)
- random.choice
- python.matplotlib/random.choice学习范例-随机生成点图
- numpy:np.random.randn
- 从np.random.normal()到正态分布的拟合
- Numpy—np.random.seed()函数的应用
- numpy函数之random.choice
- scikit-learn工具学习 - random,mgrid,np.r_ ,np.c_, scatter, axis, pcolormesh, contour, decision_function