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 ...
随机推荐
- URAL 1750 Pakhom and the Gully 计算几何+floyd
题目链接:点击打开链接 gg.. . #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cs ...
- atitit.跨语言实现备份mysql数据库 为sql文件特性 api 兼容性java c#.net php js
atitit.跨语言实现备份mysql数据库 为sql文件特性 api 兼容性java c#.net php js 1. 两个方法:: bat vs mysqldump(推荐) vs lang ...
- C++学习笔记34 模版的原理
模版在C++中具有很重要的地位.STL就是大量运用模版写出来的. 模版的长处我就不一一列举了.这里我仅仅说一下模版的原理. 当编译器遇到模版方法定义的时候,编译器进行语法检查,可是并不会编译模版.编译 ...
- codeforces #364b Cells Not Under Attack
比赛的时候 long long sum=n*n,计算不出1e10长度到数,没有搞掉. 哎,以后要注意这个地方.这个题其实不难: 统计能被攻击到的个数,然后用总的个数减掉就可以了.注意有些地方重复计算, ...
- Chrome插件开发之manifest.json
广而告之: Chrome插件之一键保存网页为PDF1.1发布 http://www.cnblogs.com/bdstjk/p/3179543.html 最近做“一键保存网页为PDF”过程中,对Chro ...
- object is not an instance of declaring class
错误原因:invoke方法的时候,应该是类的实例对象,而不是类本身 解决方法:把 PowerMockito.doReturn(index_expect).when(IndexController.cl ...
- 敏捷开发 scrum管理
项目准备阶段 1.产品经理将整体项目拆分成不同的单独模块,每个模块尽量细化到能够自成一体.例如app的登录注册模块,不能仅仅就是登录注册这两个界面,而是要将所有与这有关的需求整合到一块.要达到的效果就 ...
- html+css+JavaScript贪吃蛇
写文记录一下最近新完成的贪吃蛇游戏案例,用到了html.css和JavaScript,难度不高,适合刚入坑的同学练习,欢迎大家交流. 下面贴源码: <!DOCTYPE html> < ...
- makefile变量定义应用到c语言
makefile是为组织程序工程的,其定义的宏怎样应用到c程序中呢? 我们知道Makefile中可定义变量或导出变量,make命令可定义变量:编译器(如gcc)可通过CFLAGS定义宏. 但如何才能使 ...
- 2017-5-14 湘潭市赛 Highway 先获得直径S,T。则一开始S,T相连,然后其他的点如果离S更远那么连在S,否则T;
Highway Accepted : Submit : Time Limit : MS Memory Limit : KB Highway In ICPCCamp there were n towns ...
, use:
):
multiply the output of 
is the mean and
the standard deviation. The square of the standard deviation,
, is called the variance.
and 