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 ...
随机推荐
- android旋转动画的两种实现方式
在android开发,我们会常常使用到旋转动画,普通情况下旋转动画有两种实现方式,一种是直接通过java代码去实现,第二种是通过配置文件实现动画.以下是两种动画的基本是用法: 纯Java代码实现: / ...
- Python标准库:内置函数chr(i)
返回一个參数i表示的字符串. 比方,chr(97)返回字符"a".參数i的有效范围为0到1.114,111(0x10FFFF),其他范围的值会抛出异常ValueError. 与之相 ...
- awk之随机函数rand()和srand()
awk之随机函数rand()和srand() 分类: LINUX 文件: abcdefg ...... 现在想要随机抽取5列组成下面的内容,允许重复: cffab ...... awk -F '' ' ...
- LeetCode300. Longest Increasing Subsequence
Description Given an unsorted array of integers, find the length of longest increasing subsequence. ...
- ORACLE函数之日期时间转换函数
1. TO_CHAR 语法:TO_CHAR(X [,format]) 说明:将X按format格式转换成字符串.X是一个日期或者数字.format是一个规定了X採用何种格式转换 ...
- CentOS7安装mysql提示“No package mysql-server available
在CentOS7上安装mysql时,出现了以下的提示: 原因是: CentOS7带有MariaDB而不是MySQL,MariaDB和MySQL一样也是开元的数据库,您可以使用yum -y instal ...
- Vsphere笔记07 Vcenter 部署流程 2
7.Vcenter 部署流程 2 Vcenter 安装需求 1.硬件要求 CPU:支持VT-X技术并开启内存:4G或4G 以上 2.系统要求 Windows 2008 R2 x64 Vsp ...
- CentOS下使用MyTop实时监控MySQL
CentOS下使用MyTop实时监控MySQL MyTop的项目页面为:http://jeremy.zawodny.com/mysql/mytop/ MyTop安装 $ yum -y install ...
- CBV流程
django CBV 源码分析 FBV和CBV FBV(function base views) 就是在视图里使用函数处理请求. 在之前django的学习中,我们一直使用的是这种方式,所以不再赘述. ...
- dva解读1
1.首先定义一个app对象实现dva const app = dva({ history: createHistory(), }); // 2. Plugins app.use(createLoadi ...
, use:
):
multiply the output of 
is the mean and
the standard deviation. The square of the standard deviation,
, is called the variance.
and 