1:rand

rand(d0, d1, ..., dn)
    Random values in a given shape.
    Create an array of the given shape and populate it with
    random samples from a uniform distribution

over ``[0, 1)``.


数字区间:[0,1)

分布:均匀分布

形状:[d0,d1,...,dn]

from numpy import random
print(random.rand(3,4))
'''result
[[0.77647254 0.87714719 0.55351719 0.31369393]
[0.38578822 0.30977858 0.31366171 0.26879944]
[0.22720179 0.26118622 0.08420711 0.70508725]]
'''

2:randint

randint(low, high=None, size=None, dtype='l')
    Return random integers from `low` (inclusive) to `high` (exclusive).
    Return random integers from the "discrete uniform" distribution of
    the specified dtype in the "half-open" interval [`low`, `high`). If

`high` is None (the default), then results are from [0, `low`).


数字区间:[low,high)

分布:离散均匀分布

形状:size

from numpy import random
print(random.randint(1,10, size=(2,3)))
'''result
[[3 1 6]
[9 1 7]]
'''

3:randn

randn(d0, d1, ..., dn)
    Return a sample (or samples) from the "standard normal" distribution.
    If positive, int_like or int-convertible arguments are provided,
    `randn` generates an array of shape ``(d0, d1, ..., dn)``, filled
    with random floats sampled from a univariate "normal" (Gaussian)
    distribution of mean 0 and variance 1 (if any of the :math:`d_i` are
    floats, they are first converted to integers by truncation). A single
    float randomly sampled from the distribution is returned if no
    argument is provided.
    This is a convenience function.  If you want an interface that takes a
    tuple as the first argument, use `numpy.random.standard_normal` instead.


数字区间:(负无穷,正无穷)

分布:标准正态分布

形状:[d0,d1,...,dn]

from numpy import random
print(random.randn(3,2))
'''result
[[ 0.0456255 0.64865066]
[-0.40588788 0.0428462 ]
[ 0.46260185 -0.05147188]]
'''

4: ranf = random = sample = random_sample

random_sample(size=None)

Return random floats in the half-open interval [0.0, 1.0).

Results are from the "continuous uniform" distribution over the
stated interval.  To sample :math:`Unif[a, b), b > a` multiply
the output of `random_sample` by `(b-a)` and add `a`::

(b - a) * random_sample() + a


数字区间:[0,1)

分布:连续均匀分布

形状:size

注意:ranf、random、sample、random_sample 都是使用的random_sample方法

要想得到a到b之间的随机数,使用  (b - a) * random_sample() + a

from numpy import random
print(random.random()) #result 0.7679449887445754
print(random.random(size=(2,2)))
'''result
[[0.05636011 0.46029369]
[0.26693099 0.34289541]]
'''

5:normal

normal(loc=0.0, scale=1.0, size=None)

Draw random samples from a normal (Gaussian) distribution.

The probability density function of the normal distribution, first
derived by De Moivre and 200 years later by both Gauss and Laplace
independently [2]_, is often called the bell curve because of
its characteristic shape (see the example below).

The normal distributions occurs often in nature. For example, it
describes the commonly occurring distribution of samples influenced
by a large number of tiny, random disturbances, each with its own
unique distribution [2]_.


数字区间:(负无穷,正无穷)

分布:均值为loc,标准差为scale的正态分布

形状:size

from numpy import random
print(random.normal(0.0, 0.01, [2, 3]))
'''result
[[-0.01117429 0.00404763 0.01438945]
[ 0.00550622 -0.01674051 -0.00411558]]
'''

numpy中的random函数的更多相关文章

  1. Python数据分析--Numpy常用函数介绍(5)--Numpy中的相关性函数

    摘要:NumPy中包含大量的函数,这些函数的设计初衷是能更方便地使用,掌握解这些函数,可以提升自己的工作效率.这些函数包括数组元素的选取和多项式运算等.下面通过实例进行详细了解. 前述通过对某公司股票 ...

  2. JAVA中的Random()函数

    Java中存在着两种Random函数: 一.java.lang.Math.Random; 调用这个Math.Random()函数能够返回带正号的double值,该值大于等于0.0且小于1.0,即取值范 ...

  3. Numpy中扁平化函数ravel()和flatten()的区别

    在Numpy中经常使用到的操作由扁平化操作,Numpy提供了两个函数进行此操作,他们的功能相同,但在内存上有很大的不同. 先来看这两个函数的使用: from numpy import * a = ar ...

  4. numpy中的argsort()函数

    在阅读<机器学习实战>一书中,发现了一个比较函数是argsort() 猜测是在numpy中出现的,手动进行了测试 >>> import numpy as np >& ...

  5. numpy中np.random.seed()的详细用法

    在进行机器学习和深度学习中,我们会经常用到np.random.seed(),利用随机数种子,使得每次生成的随机数相同. numpy.randn.randn(d0,d1,...,dn) randn函数根 ...

  6. Python:numpy中的tile函数

    在学习机器学习实教程时,实现KNN算法的代码中用到了numpy的tile函数,因此对该函数进行了一番学习: tile函数位于python模块 numpy.lib.shape_base中,他的功能是重复 ...

  7. numpy中一些常用函数的用法总结

    先简单记录一下,后续补充详细的例子   1. strip()函数 s.strip(rm):s为字符串,rm为要删除的字符序列 只能删除开头或是结尾的字符或者字符串.不能删除中间的字符或是字符串 当rm ...

  8. numpy中的tile函数

    tile()函数可以很方便的生成多维数组.它有两个参数,第一个数是原始数组;第二个表示如何来生成,第一个数字表示生成几行,第二个表示每行有多少个原始数组(如果只写一个数字,那么就默认是一行). fro ...

  9. numpy中的mean()函数

    本文链接:https://blog.csdn.net/lilong117194/article/details/78397329mean() 函数定义:numpy.mean(a, axis, dtyp ...

随机推荐

  1. mysql5.7.10 源码编译安装记录 (centos6.4)【转】

    一.准备工作 1.1 卸载系统自带mysql 查看系统是否自带MySQL, 如果有就卸载了, 卸载方式有两种yum, rpm, 这里通过yum卸载 rpm -qa | grep mysql //查看系 ...

  2. Django 基于类的视图(CBV)执行流程 CBV 源码分析

    一.CBV(基于类的视图) 视图是可以调用的,它接受请求并返回响应,这不仅仅是一个函数,Django提供了一些可以用作视图的类的例子,这些允许您通过继承或mixin来构建视图并重用代码. 基本示例 D ...

  3. Monkeyrunner的相关总结

    1.1  monkeyrunner API 主要包括三个模块1.MonkeyRunner:这个类提供了用于连接monkeyrunner和设备或模拟器的方法,它还提供了用于创建用户界面显示提供了方法.2 ...

  4. Extjs 基础篇—— Function 能在定义时就能执行的方法的写法 function(){...}()

    Ext.js 中 Function能在定义时就能执行的方法的写法 function(){...}() /** * 第二部分Function:能在定义时就能执行的方法的写法 function(){... ...

  5. java基础62 JavaScript中的函数(网页知识)

    1.JavaScript中,函数的格式 function 函数名(形参列表){ 函数体; } 2.JavaScript中,函数需要注意的细节 1.在javaScript中,函数定义形参时,是不能使用v ...

  6. cuowu

    ngFor不能用于Object rowspan colspan不能绑定变量,要用attr.colspan https://stackoverflow.com/questions/35615751/wh ...

  7. (四)SpringMvc文件上传

    第一节:SpringMvc单文件上传 第二节:SpringMvc多文件上传

  8. php安装amqp扩展

    1.要安装AMQP PHP扩展,必须先安装librabbitmq库 1.1使用以下步骤下载并安装库: # 下载 git clone git://github.com/alanxz/rabbitmq-c ...

  9. Datagridview 中的checkbox 选中或勾选状态失效

    1.问题描述,先选中第一行,再取消选择,然后点击部门全选,第一行没有打钩,状态是不选中的状态. 2.分析代码 先选中第一行,单元格的单击事件中 改变选中状态为1,第一行取消选择,单元格的单击事件中 改 ...

  10. CF GYM100548 (相邻格子颜色不同的方案数 2014西安现场赛F题 容斥原理)

    n个格子排成一行,有m种颜色,问用恰好k种颜色进行染色,使得相邻格子颜色不同的方案数. integers n, m, k (1 ≤n, m ≤ 10^9, 1 ≤ k ≤ 10^6, k ≤ n, m ...