[numpy]random.choice()随机选取内容
2018-01-02 16:48
513 查看
概述:
可以从一个int数字或1维array里随机选取内容,并将选取结果放入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.
示例
官方介绍
http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.random.choice.html
可以从一个int数字或1维array里随机选取内容,并将选取结果放入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
相关文章推荐
- [numpy]random.choice()随机选取内容
- numpy.random.choice 中replace 的含义
- numpy.random.choice
- numpy的random随机值模块详解
- python.matplotlib/random.choice学习范例-随机生成点图
- 从多个textarea中随机选取一个内容
- 随机读写文件内容之RandomAccessFile类相关
- Numpy之random.randint产生随机整数
- python numpy.random生成随机数组
- 自定义Django Form中choicefield下拉菜单选取数据库内容
- enumerate(),flatnonzero(),argsort(),array_split(),numpy.random.choice()
- RandomAccessFile类学习,随机修改文件内容
- java:RandomAccessFile随机读取文件内容
- Python random模块(随机整数部分内容)
- numpy.random.choice和zeros的用法
- numpy中的random.choice()函数
- 使用随机存取文件流:RandomAccessFile实现文本文件内容的随机插入
- numpy中的random模块
- Numpy:排序及返回索引、多重复制、两个矩阵对应元素取最小值、随机选择元素
- numpy.random.shuffle(x)的用法