numpy.random.choice 中replace 的含义
来源:互联网 发布:喜马拉雅视频剪辑软件 编辑:程序博客网 时间:2024/06/05 14:17
numpy.random.choice的官方定义见这里
搬运过来如下:
numpy.random.choice(a, size=None, replace=True, p=None)
Generates a random sample from a given 1-D array
New in version 1.7.0.
- Parameters:
- 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
Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.- 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.- Returns:
samples : 1-D ndarray, shape (size,)
The generated random samples- Raises:
ValueError
If a is an int and less than zero, if a or p are not 1-dimensional, if a is an array-like of size 0, if p is not a vector of probabilities, if a and p have different lengths, or if replace=False and the sample size is greater than the population size
用人话简单解释一下:
从一维 数组
a
中选出size
个元素,a
中每个元素被选中的概率由一维数组p
定义。
可replace
是什么鬼?(每个官方解释单词都能看懂,就是不懂在说什么。。)
查了一下,原文见stackoverflow.
简单解释一下:
replace=True
: 可以从a
中反复选取同一个元素。
replace=False
:a
中同一个元素只能被选取一次。
搬运栗子:
from numpy import random as rdary = list(range(10))# usageIn[18]: rd.choice(ary, size=8, replace=False)Out[18]: array([0, 5, 9, 8, 2, 1, 6, 3]) # no repeated elementsIn[19]: rd.choice(ary, size=8, replace=True)Out[19]: array([4, 9, 8, 5, 4, 1, 1, 9]) # elements may be repeated
阅读全文
0 0
- numpy.random.choice 中replace 的含义
- numpy的random.choice函数
- numpy.random.choice
- np.random.choice 参数replace
- numpy函数之random.choice
- [numpy]random.choice()随机选取内容
- numpy中random的详解
- python中numpy-choice函数
- random.choice
- python中numpy的random模块
- numpy的random模块
- numpy的random
- numpy的random模块
- numpy的random模块
- numpy的random模块
- numpy的random模块
- numpy的random模块
- numpy的random模块
- git 分支 合并
- Python内存管理结合源码 整理补充 (未完成)
- 不定宽高元素的水平垂直居中
- 9章 进程关系
- C++中栈操作
- numpy.random.choice 中replace 的含义
- 小小项目4:贪吃蛇
- 文本自动生成研究进展与趋势
- python 并集union, 交集intersection, 差集difference
- Django url管理之include
- 算法:数的每个位数相乘等于给出的数,并且这个数是符合条件的数中最小的数
- 文章标题
- [js]圆周运动&类s运动
- Java中BIO NIO AIO