随机抽样 (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的随机函数子库——numpy.random
NumPy的随机函数子库numpy.random 导入模块:import numpy as np 1.numpy.random.rand(d0,d1,...,dn) 生成一个shape为(d0,d1, ...
- numpy.random.seed()方法
先贴参考链接: https://stackoverflow.com/questions/21494489/what-does-numpy-random-seed0-do numpy.random.se ...
- numpy.random中的shuffle和permutation以及mini-batch调整数据集(X, Y)
0. numpy.random中的shuffle和permutation numpy.random.shuffle(x) and numpy.random.permutation(x),这两个有什么不 ...
- python基础--numpy.random
# *_*coding:utf-8 *_* # athor:auto import numpy.random #rand(d0, d1, ..., dn)n维随机值 data0 = numpy.ran ...
- numpy.random 常用函数详解之排列乱序篇(Permutations)
1.numpy.random.shuffle(x) 参数:填入数组或列表. 返回值:无. 函数功能描述:对填入的数组或列表进行乱序处理,shape保持不变. 2.numpy.random.permut ...
- numpy.random 常用函数详解之简单随机数篇(Simple random data)
1.numpy.random.rand(d0,d1,d2,...,dn) 参数:d0,d1,d2,...,dn 须是正整数,用来描述生成随机数组的维度.如(3,2)代表生成3行2列的随机数组. 返回值 ...
- numpy.random.uniform()
numpy.random.uniform均匀分布 2018年06月19日 23:28:03 徐小妹 阅读数:4238 numpy.random.uniform介绍: 1. 函数原型: numpy ...
- numpy.random.randn()与numpy.random.rand()的区别(转)
numpy中有一些常用的用来产生随机数的函数,randn()和rand()就属于这其中. numpy.random.randn(d0, d1, …, dn)是从标准正态分布中返回一个或多个样本值. n ...
- 使用 numpy.random.choice随机采样
使用 numpy.random.choice随机采样: 说明: numpy.random.choice(a, size=None, replace=True, p=None) 示例: >> ...
随机推荐
- 为什么要Code Review
刚才专注看了下zwchen的博客,读到Code Reivew这一篇,觉得自己也了说话的冲动. 我们Team实施Code Reivew近5年,到今天,我们的结论是: Code Review是我们项目成功 ...
- Leetcode783.Minimum Distance Between BST Nodes二叉搜索树结点最小距离
给定一个二叉搜索树的根结点 root, 返回树中任意两节点的差的最小值. 示例: 输入: root = [4,2,6,1,3,null,null] 输出: 1 解释: 注意,root是树结点对象(Tr ...
- Tumblr,instapaper分享
<div id="bshare-custom"> <a title="分享到Tumblr" id="bshare-tumblr&qu ...
- Effective Modern C++:05右值引用、移动语义和完美转发
移动语义使得编译器得以使用成本较低的移动操作,来代替成本较高的复制操作:完美转发使得人们可以撰写接收任意实参的函数模板,并将其转发到目标函数,目标函数会接收到与转发函数所接收到的完全相同的实参.右值引 ...
- 基于Spark Mllib的Spark NLP库
SparkNLP的官方文档 1>sbt引入: scala为2.11时 libraryDependencies += "com.johnsnowlabs.nlp" %% &qu ...
- php 获取客户端的ip、地理信息、浏览器信息、本地真实ip
转自:http://www.blhere.com/948.html 这是非常实用的php常用类.获取客户端的ip.地理信息.浏览器信息.本地真实ip 1234567891011121314151617 ...
- JavaScript--for in循环访问属性用"."和[ ]的区别
// for in 循环遍历对象的时候// 内部要访问属性的时候不能点语法访问,因为for in 的key是字符串格式// 可通过方括号实现访问 for(var key in manObj) { co ...
- 在Swift中检查API的可用性
http://www.cocoachina.com/swift/20150901/13283.html 本文由CocoaChina译者ALEX吴浩文翻译自Use Your Loaf博客 原文:Chec ...
- python HTTP请求过程
- @hdu - 6594@ Double Tree
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定两棵 N 个点的树,以及树上每条边的权值 w(u, v),每 ...
, use:
):
multiply the output of 
is the mean and
the standard deviation. The square of the standard deviation,
, is called the variance.
and 