打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
numpy的random模块

随机抽样 (numpy.random)

简单的随机数据

rand(d0, d1, ..., dn)

随机值

>>> np.random.rand(3,2)array([[ 0.14022471,  0.96360618],  #random       [ 0.37601032,  0.25528411],  #random       [ 0.49313049,  0.94909878]]) #random

randn(d0, d1, ..., dn)

返回一个样本,具有标准正态分布。

Notes

For random samples from [R217]).

 

Examples

Draw samples from the distribution:

>>> mu, sigma = 0, 0.1 # mean and standard deviation>>> s = np.random.normal(mu, sigma, 1000)

Verify the mean and the variance:

>>> abs(mu - np.mean(s)) < 0.01True>>> abs(sigma - np.std(s, ddof=1)) < 0.01True

Display the histogram of the samples, along with the probability density function:

>>> import matplotlib.pyplot as plt>>> count, bins, ignored = plt.hist(s, 30, normed=True)>>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *...                np.exp( - (bins - mu)**2 / (2 * sigma**2) ),...          linewidth=2, color=‘r‘)>>> plt.show()

 

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])

齐普夫分布

随机数生成器

RandomState

Container for the Mersenne Twister pseudo-random number generator.

seed([seed])

Seed the generator.

get_state()

Return a tuple representing the internal state of the generator.

set_state(state)

Set the internal state of the generator from a tuple.
幸运之神的降临,往往只是因为你多看了一眼,多想了一下,多走了一步。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
如何驾驭Matplotlib?<Part1>
要想成为一名月入几万的数据分析师,绘制图表是必会的!实例教程
用 Python 生成直方图:你会怎么做?
python+opencv图像处理(十三)
机器学习算法的随机数据生成
emcee——Quickstart
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服