前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >numpy: np.random模块 探究(源码)

numpy: np.random模块 探究(源码)

作者头像
JNingWei
发布2018-09-28 15:56:19
1.3K0
发布2018-09-28 15:56:19
举报
文章被收录于专栏:JNing的专栏JNing的专栏

官方api定义

From Random sampling

Random sampling (numpy.random) Simple random data rand(d0, d1, …, dn) Random values in a given shape . randn(d0, d1, …, dn) Return a sample (or samples) from the “standard normal” distribution . randint(low[, high, size, dtype]) Return random integers from low (inclusive) to high (exclusive) . random_integers(low[, high, size]) Random integers of type np.int between low and high, inclusive . random_sample([size]) Return random floats in the half-open interval [0.0, 1.0) . random([size]) Return random floats in the half-open interval [0.0, 1.0) . ranf([size]) Return random floats in the half-open interval [0.0, 1.0) . sample([size]) Return random floats in the half-open interval [0.0, 1.0) . choice(a[, size, replace, p]) Generates a random sample from a given 1-D array bytes(length) Return random bytes.

实验代码

randint(low[, high, size, dtype]): Return random integers from low (inclusive) to high (exclusive). 从低(包括)到高(排除)返回随机整数。

代码语言:javascript
复制
import numpy as np

# randint(low[, high, size, dtype])    Return random integers from low (inclusive) to high (exclusive).
# randint(low[, high, size, dtype])    从低(包括)到高(排除)返回随机整数。
list_randint = np.random.randint(low=10, high=20, size=[1, 5])
print list_randint
代码语言:javascript
复制
[[16 14 13 16 17]]

random_integers(low[, high, size]): Random integers of type np.int between low and high, inclusive. 类型为np.int的随机整数,包括低和高。

代码语言:javascript
复制
import numpy as np

# random_integers(low[, high, size])    Random integers of type np.int between low and high, inclusive.
# random_integers(low[, high, size])    类型为np.int的随机整数,包括低和高。
list_random_integers = np.random.random_integers(low=10, high=20, size=[1, 5])
print list_random_integers
代码语言:javascript
复制
[[17 11 12 20 12]]

rand(d0, d1, …, dn): Random values in a given shape. 给定形状的随机值。

代码语言:javascript
复制
import numpy as np

# rand(d0, d1, ..., dn)    Random values in a given shape.
# rand(d0, d1, ..., dn)    给定形状的随机值。
list_rand = np.random.rand(5)
print list_rand
代码语言:javascript
复制
[ 0.79382535  0.5270354   0.3732075   0.39917033  0.99818847]

randn(d0, d1, …, dn): Return a sample (or samples) from the “standard normal” distribution. 从“标准正常”分发中返回样本(或样本)。

代码语言:javascript
复制
import numpy as np

# randn(d0, d1, ..., dn)    Return a sample (or samples) from the “standard normal” distribution.
# randn(d0, d1, ..., dn)    从“标准正常”分发中返回样本(或样本)。
list_randn = np.random.randn(5)
print list_randn
代码语言:javascript
复制
[-0.35846856  0.70406236 -0.65582092  1.20919057 -0.29739695]

random([size]): Return random floats in the half-open interval [0.0, 1.0). 在半开间隔[0.0,1.0]中返回随机浮点数。

代码语言:javascript
复制
import numpy as np

# random([size])    Return random floats in the half-open interval [0.0, 1.0).
# random([size])    在半开间隔[0.0,1.0]中返回随机浮点数。
list_random_1 = np.random.random(size=5)
print list_random_1
list_random_2 = np.random.random(size=[1, 5])
print list_random_2
代码语言:javascript
复制
[ 0.17053837  0.54069506  0.21863745  0.82232234  0.30818991]
[[ 0.66736397  0.86776538  0.0208963   0.50920261  0.61017499]]


本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年09月01日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 官方api定义
    • From Random sampling:
    • 实验代码
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档