均匀分布,随机生成下一个实数,在 [low, high) 范围内。
low : 随机数的最小值,包含该值。
high : 随机数的最大值,不包含该值。
https://blog.csdn.net/u013920434/article/details/52507173 讲的很全面
https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.random.uniform.html 官方讲解
a = np.random.uniform(1, 2, 10)
>>> a
array([1.78110153, 1.08004137, 1.52783342, 1.4495069 , 1.14119001,
1.53451488, 1.35288078, 1.2797133 , 1.75361729, 1.1551278 ])
>>> a.shape
(10,)
>>> b = np.random.uniform(1, 2, 10)[:, np.newaxis] #加了一个维度
>>> b
array([[1.19651492],
[1.39541099],
[1.03515532],
[1.85664151],
[1.84396349],
[1.55697423],
[1.14567357],
[1.11043705],
[1.80660254],
[1.50724142]])
>>> b.shape
(10, 1)
numpy.random.
random
(size = None )(0, 1)中返回随机浮点数。
>>> print(np.random.random())
0.4362833489716911
>>> print(np.random.random(5,))
[0.23883434 0.56420743 0.97575548 0.44025629 0.73052107]
>>> print( np.random.random((2,4))) # 定义具体维度时random后需2层括号
[[0.56629049 0.25066895 0.22551347 0.69089366]
[0.86297426 0.45869556 0.07899109 0.94200317]]
https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.random.random.html
---------------------
作者:qfpkzheng
来源:CSDN
原文:https://blog.csdn.net/qfpkzheng/article/details/79061601
版权声明:本文为博主原创文章,转载请附上博文链接!# 参数意思分别 是从a 中以概率P,随机选择3个, p没有指定的时候相当于是一致的分布
a1 = np.random.choice(a=5, size=3, replace=False, p=None)
print(a1)
# 非一致的分布,会以多少的概率提出来
a2 = np.random.choice(a=5, size=3, replace=False, p=[0.2, 0.1, 0.3, 0.4, 0.0])
print(a2)
# replacement 代表的意思是抽样之后还放不放回去,如果是False的话,那么出来的三个数都不一样,如果是
True的话, 有可能会出现重复的,因为前面的抽的放回去了。
---------------------
作者:超级杰哥
来源:CSDN
原文:https://blog.csdn.net/autoliuweijie/article/details/51982514
版权声明:本文为博主原创文章,转载请附上博文链接!a : 1-D array-like or int
If an ndarray, a random sample is generated from its elements.
If an int, the random sample is generated as if a was np.arange(n)size : int or tuple of ints, optional
replace : boolean, optional
Whether the sample is with or without replacementp : 1-D array-like, optional
The probabilities associated with each entry in a. If not given the sample assumes a uniform distribution over all entries in a.>>> np.random.choice(5, 3) array([0, 3, 4]) >>> np.random.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0]) array([3, 3, 0]) >>> np.random.choice(5, 3, replace=False) array([3,1,0]) >>> np.random.choice(5, 3, replace=False, p=[0.1, 0, 0.3, 0.6, 0]) array([2, 3, 0]) >>> aa_milne_arr = ['pooh', 'rabbit', 'piglet', 'Christopher'] >>> np.random.choice(aa_milne_arr, 5, p=[0.5, 0.1, 0.1, 0.3]) array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'],