numpy: np.random模块 探究(源码)
来源:互联网 发布:windows优化大师固态 编辑:程序博客网 时间:2024/05/18 00:23
官方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).
从低(包括)到高(排除)返回随机整数。
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
[[16 14 13 16 17]]
random_integers(low[, high, size]):
Random integers of type np.int between low and high, inclusive.
类型为np.int的随机整数,包括低和高。
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
[[17 11 12 20 12]]
rand(d0, d1, …, dn):
Random values in a given shape.
给定形状的随机值。
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
[ 0.79382535 0.5270354 0.3732075 0.39917033 0.99818847]
randn(d0, d1, …, dn):
Return a sample (or samples) from the “standard normal” distribution.
从“标准正常”分发中返回样本(或样本)。
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
[-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]中返回随机浮点数。
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_1list_random_2 = np.random.random(size=[1, 5])print list_random_2
[ 0.17053837 0.54069506 0.21863745 0.82232234 0.30818991][[ 0.66736397 0.86776538 0.0208963 0.50920261 0.61017499]]
- numpy: np.random模块 探究(源码)
- numpy:np.random.randn
- np.random模块
- numpy 随机数种类np.random.RandomState、np.random.rand、np.random.random、np.random_sample
- Numpy之random模块
- numpy的random模块
- numpy的random模块
- numpy的random模块
- numpy random 模块
- Numpy之random模块
- numpy的random模块
- numpy中的random模块
- numpy的random模块
- numpy的random模块
- numpy的random模块
- python的np.random模块
- Numpy学习—np.random.randn()、np.random.rand()和np.random.randint()
- NumPy random模块的使用
- Android 数据存储(三) 数据库存储
- yii2底层源码分析1
- SpringBoot中的WebSocket点对点发送消息
- Centos6 升级Git版本
- C++中的explicit关键字
- numpy: np.random模块 探究(源码)
- 【互联网安全】阿里云安全专家为你详细解读内容安全及防护
- celery分布式队列任务
- 疯狂Android讲义(第3版)学习笔记(第四章---Activity与Fragment)
- 深入理解Apache Flink核心技术
- JAVA必背面试题和项目面试通关要点
- 面向对象中装饰模式的理解
- Python实现感知器
- 理解Oauth2.0原理的好文章(转自阮一峰老师)