np.random.random()
區(qū)間 [0,1)內(nèi)均勻分布的浮點(diǎn)數(shù)樣本值
參數(shù)為一個(gè)數(shù)字或元組
>>> np.random.random((3,3))
array([[0.29662866, 0.49017285, 0.36385719],
[0.75705946, 0.83283902, 0.43799933],
[0.96813892, 0.52336287, 0.69897707]])
np.random.rand(d1,d2,d3,...dn)
返回一個(gè)或一組服從“0~1"均勻分布的隨機(jī)樣本值。隨機(jī)樣本取值范圍是[0,1),不包括1。
參數(shù)為一組數(shù)字
>>> np.random.rand(3,3)
array([[0.97490882, 0.62584059, 0.64094061],
[0.94944701, 0.60058469, 0.40378451],
[0.98257808, 0.49637092, 0.82605012]])
np.random.randn(d1,d2,...dn)
生成一個(gè)浮點(diǎn)數(shù)或N維浮點(diǎn)數(shù)組迫悠,取數(shù)范圍:正態(tài)分布的隨機(jī)樣本數(shù)
參數(shù)為一組數(shù)字
>>> np.random.randn(3,3)
array([[-0.13166095, -0.39784247, -1.40062493],
[-1.18981662, -0.11726426, 1.53941094],
[-1.61486293, -0.52929011, -0.4025181 ]])
np.random.randint(low, high=None, size=None, dtype='l')
生成一個(gè)整數(shù)或N維整數(shù)數(shù)組,取數(shù)范圍:若high不為None時(shí)承边,取[low,high)之間隨機(jī)整數(shù)酗昼,否則取值[0,low)之間隨機(jī)整數(shù)逸尖。
>>> np.random.randint(1,9,5)
array([2, 5, 8, 2, 4])
np.random.normal()
np.random.normal()的意思是一個(gè)正態(tài)分布锄开,normal這里是正態(tài)的意思素标。numpy.random.normal(loc=0,scale=1e-2,size=shape)
參數(shù)loc(float):正態(tài)分布的均值,對(duì)應(yīng)著這個(gè)分布的中心萍悴。loc=0說(shuō)明這一個(gè)以Y軸為對(duì)稱軸的正態(tài)分布头遭,
參數(shù)scale(float):正態(tài)分布的標(biāo)準(zhǔn)差寓免,對(duì)應(yīng)分布的寬度,scale越大计维,正態(tài)分布的曲線越矮胖袜香,scale越小,曲線越高瘦鲫惶。
參數(shù)size(int 或者整數(shù)元組):輸出的值賦在shape里蜈首,默認(rèn)為None。
>>> np.random.normal(loc=3,scale=3,size=10)
array([ 3.57732629, 4.03319904, 4.90395824, 0.78545378, -1.12050064,
2.92450181, 2.94470717, 3.10484983, 2.18553684, 4.14682614])
np.random.standard_normal(loc=0.0, scale=1.0, size=None)
生產(chǎn)一個(gè)浮點(diǎn)數(shù)或N維浮點(diǎn)數(shù)組剑按,取數(shù)范圍:標(biāo)準(zhǔn)正態(tài)分布隨機(jī)樣本
>>> np.random.standard_normal((3,3))
array([[ 0.42480835, 1.80721169, 2.11125768],
[ 0.63185324, -2.34764863, 0.41590828],
[-1.23066381, 1.72688409, 1.88816023]])
np.random.uniform(ow=0.0, high=1.0, size=None)
從一個(gè)均勻分布[low,high)中隨機(jī)采樣疾就,注意定義域是左閉右開(kāi),即包含low艺蝴,不包含high.
>>> np.random.uniform(low=-5,high=5,size=10)
array([ 2.91948933, -1.98224335, 0.12850215, -1.49213414, 0.59583766,
-1.19721507, -3.60499001, 4.89615872, -4.90105933, -2.76338066])
np.empty(shape[, dtype, order])
np.empty()返回一個(gè)隨機(jī)元素的矩陣,大小按照參數(shù)定義鸟废。
>>> np.empty((2,2))
array([[1.18575755e-322, 9.88255749e-312],
[4.94065646e-324, 0.00000000e+000]])