有关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]])

 

 

posted @ 2018-01-26 14:40  Fintech带你飞  阅读(310)  评论(0编辑  收藏  举报