import numpy as np
”’
1)rand(d0, d1, …, dn)
Create an array of the given shape and populate(居住于) it with
random samples from a uniform distribution
over [0, 1)
. 0~1的均匀分布
Parameters
----------
d0, d1, ..., dn : int, optional
The dimensions of the returned array, should all be positive.
If no argument is given a single Python float is returned.
Returns
-------
out : ndarray, shape ``(d0, d1, ..., dn)``
Random values.
”’
rand=np.random.rand(3,2)
print(“rand:”,rand)
”’
2)np.random.randn(d0, d1, …, dn) 0~1 标准正态分布 standard normal
”’
randn=np.random.randn(3,2)
print(“randn:”,randn)
”’
3)randint(low[,high,shape]) []中为可选参数
”’
randint=np.random.randint(100,200,(2,3))
”’
4)
shuffle [ˈʃʌfl]乱序 shuffle(x) 改变数组x本身
permutation 置换顺序 permutation(x) 不改变数组x
根据数组最外维进行随机排列,内部的顺序不变
”’
x=np.arange(20,40,step=1,dtype=int).reshape(4,5)
np.random.shuffle(x)
print(“shuffle_x:”,x)
”’
5)
choice(x[,size,replace,p])
从一维数组x中抽取元素,每个元素的抽取概率为p(p为与x同shape的概率数组)中的对应概率,形成size形状的新数组
replace 默认为false 不可重用元素
”’
x.resize((20,))
print(“x_resize:”,x)
print(“choice:”,np.random.choice(x,size=(3,4),p=x/np.sum(x)))
6)均匀分布
print(“np.random.uniform(20,40,(2,4)):”,np.random.uniform(20,40,(2,4)))
7)正态分布(均值,方差,shape)
print(“np.random.normal(0,1,(3,4)):”,np.random.normal(0,1,(3,4)))
8)泊松分布
print(“np.random.poisson(0.3,(2,4)):”,np.random.poisson(0.3,(2,4)))