numpy.random.uniform介绍:

1. 函数原型:  numpy.random.uniform(low,high,size)  ==》也即其他函数是对该函数的进一步封装

功能:从一个均匀分布[low,high)中随机采样,注意定义域是左闭右开,即包含low,不包含high.

参数介绍:
    
    low: 采样下界,float类型,默认值为0;
    high: 采样上界,float类型,默认值为1;
    size: 输出样本数目,为int或元组(tuple)类型,例如,size=(m,n,k), 则输出m*n*k个样本,缺省时输出1个值。

返回值:ndarray类型,其形状和参数size中描述一致。

这里顺便说下ndarray类型,表示一个N维数组对象,其有一个shape(表维度大小)和dtype(说明数组数据类型的对象),使用zeros和ones函数可以创建数据全0或全1的数组,原型:

numpy.ones(shape,dtype=None,order='C'),
其中,shape表数组形状(m*n),dtype表类型,order表是以C还是fortran形式存放数据。

numpy.random.uniform(low=0.0, high=1.0, size=None)

2. 类似uniform,还有以下随机数产生函数:

a. randint: 原型:numpy.random.randint(low, high=None, size=None, dtype='l'),产生随机整数;
    b. random_integers: 原型: numpy.random.random_integers(low, high=None, size=None),在闭区间上产生随机整数;
    c. random_sample: 原型: numpy.random.random_sample(size=None),在[0.0,1.0)上随机采样;
    d. random: 原型: numpy.random.random(size=None),和random_sample一样,是random_sample的别名;
    e. rand: 原型: numpy.random.rand(d0, d1, ..., dn),产生d0 - d1 - ... - dn形状的在[0,1)上均匀分布的float型数。
    f. randn: 原型:numpy.random.randn(d0,d1,...,dn),产生d0 - d1 - ... - dn形状的标准正态分布的float型数。

3. numpy.random.RandomState:

  “Container for the Mersenne Twister pseudo-random number generator.” 翻译过来为:

它是一个容器,用来存储采用梅森旋转产生伪随机数的算法。

输入参数:seed,可选项{None, int, array_like},没有给定的话,函数随机选一个起始点,
             这样深度学习的结果可能接近,但不完全相同,如果给定一个seed,则结果是deterministic,
             是确定的,但给定不给定seed对输出随机数并没有影响,只是相当于给定了一个初始点,后面
             的数也是基于这个seed而产生。

4.np.random.choice

RandomState.choice(a, size=None, replace=True, p=None)
  a : 1-D array-like or int    If an ndarray, a random sample is generated from its elements. 
      如果是ndarray数组,随机样本在该数组获取(取数据元素),    If an int, the random sample is generated as if a was np.arange(n)
      如果是整型数据随机样本生成类似np.arange(n)    
  size : int or tuple of ints, optional 
      大小:整型或整型元组中元素个数,可选
  replace : boolean, optional
      替换:布尔型,可选    Whether the sample is with or without replacement
      样本是否有重复值(False,没有;True,有;默认:True)
  见例子3
  p : 1-D array-like, optional
      1维数组,可选
      The probabilities associated with each entry in a. If not given the sample assumes a uniform distribution over all entries in a.
   和a里的每个输入联系,如果没有该参数,默认假设a里的每个输入等概率出现。(和a中元素一一对应,表示该元素出现的概率,概率大的,出现较多)

p=3
Z=np.zeros((5,5))
z=np.copy(Z) choice=np.random.choice(range(5*5), p, replace=False)
print(choice)
np.put(Z,choice,1)
print(Z) np.put(z,np.random.choice(range(3*3),p,replace=False),1)
Z
[12 24  8]
[[0. 0. 0. 0. 0.]
[0. 0. 0. 1. 0.]
[0. 0. 1. 0. 0.]
[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 1.]]
Out[103]:
array([[0., 0., 0., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 1.]])

最新文章

  1. redis 间断性耗时长问题解决
  2. java.util.zip.ZipException: invalid entry size 解决办法
  3. 【openGL】四面体
  4. 深入浅出设计模式——享元模式(Flyweight Pattern)
  5. .net实现调用本地exe等应用程序的办法总结
  6. 交换机和VLAN
  7. [RxJS] AsyncSubject
  8. python调webservice和COM接口
  9. MultipartResolver 文件上传
  10. apicloud教程3 (转载)
  11. Chris Richardson微服务翻译:构建微服务之微服务架构的进程通讯
  12. hive新特性reflect函数介绍
  13. 再深刻理解下web3.js中estimateGas如何计算智能合约消耗的gas量
  14. Asp.net MVC 中 CodeFirst 开发模式实例
  15. gdb 命令汇总
  16. POJ 3616 Milking Time 【DP】
  17. Java反射,参数为数组
  18. List,Set,Collection,Collections比较
  19. Codeforces 833A The Meaningless Game - 数论 - 牛顿迭代法 - 二分法
  20. python2 安装scrapy出现错误提示解决办法~

热门文章

  1. 正式发布! .NET开发控件集ComponentOne 新版本加入Blazor UI
  2. 【AtCoder】ARC070
  3. k-近邻(KNN) 算法预测签到位置
  4. gitlab LFS 的应用实践
  5. Istio技术与实践01: 源码解析之Pilot多云平台服务发现机制
  6. C#字典转对象
  7. 怎样监听HTTP请求的成功、失败与进行时
  8. django+uwsgi+nginx: websock 报502/400
  9. Jmeter4.0---- jmeter中写入java代码_简单了解(15)
  10. myEclipse10安装以及破解