zoukankan      html  css  js  c++  java
  • 有关numpy.random下的API具体含义

    1.numpy.random.random(size=None)

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

    返回size大小的左闭右开区间[0.0,1.0)之间的任意数

    例子:

    import numpy as np

    >>> np.random.random((3,2))

    array([[ 0.14334653,  0.77302772],

           [ 0.29343   ,  0.3616797 ],

           [ 0.74033689,  0.27422447]])

     

    2.numpy.random.random_sample()

     

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

     

    >>> np.random.random_sample()

    0.20764369973602625

     

    >>> np.random.random_sample((5,))

    array([ 0.92364552,  0.20655286,  0.22086714,  0.89360228,  0.2601571 ])

     

    Three-by-two array of random numbers from [-5, 0):

     >>> 5 * np.random.random_sample((3, 2)) - 5

    array([[-4.13201957, -1.74491577],

           [-4.40046347, -4.26736193],

           [-4.70610327, -0.24798093]])

     

    1和2是相同的

     

    3.numpy.random.randint(lowhigh=Nonesize=None)

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

    >>> np.random.randint(2, size=10)

    array([0, 1, 0, 0, 1, 1, 0, 1, 0, 1])

     

    >>> np.random.randint(1, size=10)

    array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

     

    >>> np.random.randint(5, size=(2, 4))

    array([[1, 1, 4, 3],

           [1, 3, 4, 2]])

     

     

    4.numpy.random.permutation

     

    Randomly permute a sequence, or return a permuted range.随机对序列进行重新排列,或者返回一个重新排列的范围

    举例如:

    >>> np.random.permutation(10)
    array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6])
    
    >>> np.random.permutation([1, 4, 9, 12, 15])
    array([15,  1,  9,  4, 12])
    
    >>> arr = np.arange(9).reshape((3, 3))
    >>> np.random.permutation(arr)
    array([[6, 7, 8],
           [0, 1, 2],
           [3, 4, 5]])

     

     

  • 相关阅读:
    Nutch分类搜索
    ubnutu命令行操作以及打开文件
    关于获取字符串的某一段值的问题
    汗。。华夏名网挂了
    “System.OutOfMemoryException”类型的异常在 mscorlib.dll 中发生,但未在用户代码中进行处理
    vs2008中无法添加数据连接之解决方案
    DockingManager的使用入门
    C# + .net下使用serialPort做串口开发 1
    为处理 InvalidOperationException. String[1]: the Size property has an invalid size of 0.
    未处理的“System.StackOverflowException”类型的异常出现在 mscorlib.dll
  • 原文地址:https://www.cnblogs.com/yanmk/p/8359426.html
Copyright © 2011-2022 走看看