numpy的random模块详细解析
随机抽样 (numpy.random)
简单的随机数据
|
rand(d0, d1, ..., dn) |
随机值 >>> np.random.rand(3,2) |
|
randn(d0, d1, ..., dn) |
返回一个样本,具有标准正态分布。 Notes For random samples from sigma * np.random.randn(...) + mu Examples >>> np.random.randn() Two-by-four array of samples from N(3, 6.25): >>> 2.5 * np.random.randn(2, 4) + 3 |
|
randint(low[, high, size]) |
返回随机的整数,位于半开区间 [low, high)。 >>> np.random.randint(2, size=10) Generate a 2 x 4 array of ints between 0 and 4, inclusive: >>> np.random.randint(5, size=(2, 4)) |
|
random_integers(low[, high, size]) |
返回随机的整数,位于闭区间 [low, high]。 Notes To sample from N evenly spaced floating-point numbers between a and b, use: a + (b - a) * (np.random.random_integers(N) - 1) / (N - 1.) Examples >>> np.random.random_integers(5) Choose five random numbers from the set of five evenly-spaced numbers between 0 and 2.5, inclusive (i.e., from the set >>> 2.5 * (np.random.random_integers(5, size=(5,)) - 1) / 4. Roll two six sided dice 1000 times and sum the results: >>> d1 = np.random.random_integers(1, 6, 1000) Display results as a histogram: >>> import matplotlib.pyplot as plt |
|
random_sample([size]) |
返回随机的浮点数,在半开区间 [0.0, 1.0)。 To sample (b - a) * random_sample() + a Examples >>> np.random.random_sample() Three-by-two array of random numbers from [-5, 0): >>> 5 * np.random.random_sample((3, 2)) - 5 |
|
random([size]) |
返回随机的浮点数,在半开区间 [0.0, 1.0)。 (官网例子与random_sample完全一样) |
|
ranf([size]) |
返回随机的浮点数,在半开区间 [0.0, 1.0)。 (官网例子与random_sample完全一样) |
|
sample([size]) |
返回随机的浮点数,在半开区间 [0.0, 1.0)。 (官网例子与random_sample完全一样) |
|
choice(a[, size, replace, p]) |
生成一个随机样本,从一个给定的一维数组 Examples Generate a uniform random sample from np.arange(5) of size 3: >>> np.random.choice(5, 3) Generate a non-uniform random sample from np.arange(5) of size 3: >>> np.random.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0]) Generate a uniform random sample from np.arange(5) of size 3 without replacement: >>> np.random.choice(5, 3, replace=False) Generate a non-uniform random sample from np.arange(5) of size 3 without replacement: >>> np.random.choice(5, 3, replace=False, p=[0.1, 0, 0.3, 0.6, 0]) Any of the above can be repeated with an arbitrary array-like instead of just integers. For instance: >>> aa_milne_arr = [‘pooh‘, ‘rabbit‘, ‘piglet‘, ‘Christopher‘] |
|
bytes(length) |
返回随机字节。 >>> np.random.bytes(10) |
排列
|
shuffle(x) |
现场修改序列,改变自身内容。(类似洗牌,打乱顺序) >>> arr = np.arange(10) This function only shuffles the array along the first index of a multi-dimensional array: >>> arr = np.arange(9).reshape((3, 3)) |
|
permutation(x) |
返回一个随机排列 >>> np.random.permutation(10) >>> np.random.permutation([1, 4, 9, 12, 15]) >>> arr = np.arange(9).reshape((3, 3)) |
分布
|
beta(a, b[, size]) |
贝塔分布样本,在 [0, 1]内。 |
|
binomial(n, p[, size]) |
二项分布的样本。 |
|
chisquare(df[, size]) |
卡方分布样本。 |
|
dirichlet(alpha[, size]) |
狄利克雷分布样本。 |
|
exponential([scale, size]) |
指数分布 |
|
f(dfnum, dfden[, size]) |
F分布样本。 |
|
gamma(shape[, scale, size]) |
伽马分布 |
|
geometric(p[, size]) |
几何分布 |
|
gumbel([loc, scale, size]) |
耿贝尔分布。 |
|
hypergeometric(ngood, nbad, nsample[, size]) |
超几何分布样本。 |
|
laplace([loc, scale, size]) |
拉普拉斯或双指数分布样本 |
|
logistic([loc, scale, size]) |
Logistic分布样本 |
|
lognormal([mean, sigma, size]) |
对数正态分布 |
|
logseries(p[, size]) |
对数级数分布。 |
|
multinomial(n, pvals[, size]) |
多项分布 |
|
multivariate_normal(mean, cov[, size]) |
多元正态分布。 >>> mean = [0,0] >>> import matplotlib.pyplot as plt |
|
negative_binomial(n, p[, size]) |
负二项分布 |
|
noncentral_chisquare(df, nonc[, size]) |
非中心卡方分布 |
|
noncentral_f(dfnum, dfden, nonc[, size]) |
非中心F分布 |
|
normal([loc, scale, size]) |
正态(高斯)分布 Notes The probability density for the Gaussian distribution is
where The function has its peak at the mean, and its “spread” increases with the standard deviation (the function reaches 0.607 times its maximum at Examples Draw samples from the distribution: >>> mu, sigma = 0, 0.1 # mean and standard deviation Verify the mean and the variance: >>> abs(mu - np.mean(s)) < 0.01 Display the histogram of the samples, along with the probability density function: >>> import matplotlib.pyplot as plt |
|
pareto(a[, size]) |
帕累托(Lomax)分布 |
|
poisson([lam, size]) |
泊松分布 |
|
power(a[, size]) |
Draws samples in [0, 1] from a power distribution with positive exponent a - 1. |
|
rayleigh([scale, size]) |
Rayleigh 分布 |
|
standard_cauchy([size]) |
标准柯西分布 |
|
standard_exponential([size]) |
标准的指数分布 |
|
standard_gamma(shape[, size]) |
标准伽马分布 |
|
standard_normal([size]) |
标准正态分布 (mean=0, stdev=1). |
|
standard_t(df[, size]) |
Standard Student’s t distribution with df degrees of freedom. |
|
triangular(left, mode, right[, size]) |
三角形分布 |
|
uniform([low, high, size]) |
均匀分布 |
|
vonmises(mu, kappa[, size]) |
von Mises分布 |
|
wald(mean, scale[, size]) |
瓦尔德(逆高斯)分布 |
|
weibull(a[, size]) |
Weibull 分布 |
|
zipf(a[, size]) |
齐普夫分布 |
随机数生成器
| Container for the Mersenne Twister pseudo-random number generator. | |
|
seed([seed]) |
Seed the generator. |
| Return a tuple representing the internal state of the generator. | |
|
set_state(state) |
Set the internal state of the generator from a tuple. |
numpy的random模块详细解析的更多相关文章
- numpy的random模块
随机抽样 (numpy.random) 简单的随机数据 rand(d0, d1, ..., dn) 随机值 >>> np.random.rand(3,2) array([[ 0.14 ...
- python中numpy的random模块
1. rand(d0,d1,.....,dn)产生[0,1]的浮点随机数,括号里面的参数可以指定产生数组的形状 例如:np.random.rand(3,2)则产生 3×2的数组,里面的数是0-1 ...
- 【numpy】新版本中numpy(numpy>1.17.0)中的random模块
numpy是Python中经常要使用的一个库,而其中的random模块经常用来生成一些数组,本文接下来将介绍numpy中random模块的一些使用方法. 首先查看numpy的版本: import nu ...
- numpy.random模块常用函数解析
numpy.random模块中常用函数解析 numpy.random模块官方文档 1. numpy.random.rand(d0, d1, ..., dn)Create an array of the ...
- numpy.random模块用法总结
from numpy import random numpy.random.uniform(low=0.0, high=1.0, size=None) 生出size个符合均分布的浮点数,取值范围为[l ...
- python-Day5-深入正则表达式--冒泡排序-时间复杂度 --常用模块学习:自定义模块--random模块:随机验证码--time & datetime模块
正则表达式 语法: mport re #导入模块名 p = re.compile("^[0-9]") #生成要匹配的正则对象 , ^代表从开头匹配,[0 ...
- Unity加载模块深度解析(网格篇)
在上一篇 加载模块深度解析(一)中,我们重点讨论了纹理资源的加载性能.这次,我们再来为你揭开其他主流资源的加载效率. 这是侑虎科技第53篇原创文章,欢迎转发分享,未经作者授权请勿转载.同时如果您有任何 ...
- include_path详细解析
include_path详细解析 原文地址:http://www.laruence.com/2010/05/04/1450.html 1.php默认的包含路径为 .;C:\php\pear 即 ...
- 转:二十一、详细解析Java中抽象类和接口的区别
转:二十一.详细解析Java中抽象类和接口的区别 http://blog.csdn.net/liujun13579/article/details/7737670 在Java语言中, abstract ...
随机推荐
- 【应用篇】Activiti外置表单实例demo(四)
在这里我想说的外置表单.是说我们将我们自己的jsp(.form,.html)等页面上传到工作流的数据库中,当任务运行到当前结点时.给我们像前台发送绑定好的表单. 此处是给表单绑定表单的过程 water ...
- LeetCode406. Queue Reconstruction by Height Add to List
Description Suppose you have a random list of people standing in a queue. Each person is described b ...
- Magical GCD UVA 1642 利用约数个数少来优化 给定n个数,求使连续的一段序列的所有数的最大公约数*数的数量的值最大。输出这个最大值。
/** 题目:Magical GCD UVA 1642 链接:https://vjudge.net/problem/UVA-1642 题意:给定n个数,求使连续的一段序列的所有数的最大公约数*数的数量 ...
- Discuz二次开发手册
Discuz文件说明,有助于discuz爱好者,进行自己的开发,在这里提供方便 admincp.php——后台系统设置主程序文件,一般只处理菜单的显示的访问权限,不处理管理控制. ajax.php—— ...
- MongoDB API和python操作
安装 下载mongodb的版本,两点注意 根据业界规则,偶数为稳定版,如1.6.X,奇数为开发版,如1.7.X 32bit的mongodb最大只能存放2G的数据,64bit就没有限制 到官网,选择合适 ...
- Servlet线程安全2
Servlet的多线程机制 Servlet体系结构是建立在Java多线程机制之上的,它的生命周期是由Web容器负责的.当客户端第一次请求某个Servlet时,Servlet容器将会根据web.xml配 ...
- 浅谈usort、uasort、uksort
前言:这三个函数都是php提供给开发者自定义的数组排序函数. 1.usort:按值排序,索引重新定义 a.基础案例 //自定义比较的函数 function mysort($a,$b){ if($a = ...
- 浅谈DNS
什么叫域名解析 域名解析是把域名指向网站空间IP,让人们通过注册的域名可以方便地访问到网站一种服务.IP地址是网络上标识站点的数字地址,为了方便记忆,采用域名来代替IP地址标识站点地址.域名解析就是域 ...
- GOCR v0.50 原理分析
一,简介: GOCR是一个c写的开源OCR库,GNU Public License,作者:Joerg Schulenburg 项目主页:http://jocr.sourceforge.net/inde ...
- python3 - property的使用
传统的绑定属性值,会把属性暴露出去,而且无法检查参数是否合法,如下: class Test(object): def __int__(self,age): self.age = age 为了检查参数 ...
, use:
):
multiply the output of 
is the mean and
the standard deviation. The square of the standard deviation,
, is called the variance.
and 