numpy中的隨機(jī)打亂數(shù)據(jù)方法np.random.shuffle解讀_第1頁
numpy中的隨機(jī)打亂數(shù)據(jù)方法np.random.shuffle解讀_第2頁
numpy中的隨機(jī)打亂數(shù)據(jù)方法np.random.shuffle解讀_第3頁
numpy中的隨機(jī)打亂數(shù)據(jù)方法np.random.shuffle解讀_第4頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

第numpy中的隨機(jī)打亂數(shù)據(jù)方法np.random.shuffle解讀目錄numpy隨機(jī)打亂數(shù)據(jù)方法np.random.shufflenumpy隨機(jī)生成數(shù)據(jù)問題用numpy.random模塊來生成隨機(jī)數(shù)組用random模塊自己構(gòu)造總結(jié)

numpy隨機(jī)打亂數(shù)據(jù)方法np.random.shuffle

importnumpyasnp

#實驗可得每次shuffle后數(shù)據(jù)都被打亂,這個方法可以在機(jī)器學(xué)習(xí)訓(xùn)練

#的時候在每個epoch結(jié)束后將數(shù)據(jù)重新洗牌進(jìn)入下一個epoch的學(xué)習(xí)

num=np.arange(20)

print(num)

np.random.shuffle(num)

print(num)

num1=np.arange(20)

print(num1)

np.random.shuffle(num1)

print(num1)

np.random.shuffle(num1)

print(num1)

[012345678910111213141516171819]

[151991421236184816010171371511]

[012345678910111213141516171819]

[241314111791951215718163101806]

[811136197912431014152101718165]

numpy隨機(jī)生成數(shù)據(jù)問題

用numpy.random模塊來生成隨機(jī)數(shù)組

1.np.random.rand用于生成[0.0,1.0)之間的隨機(jī)浮點(diǎn)數(shù),當(dāng)沒有參數(shù)時,返回一個隨機(jī)浮點(diǎn)數(shù),當(dāng)有一個參數(shù)時,返回該參數(shù)長度大小的一維隨機(jī)浮點(diǎn)數(shù)數(shù)組,參數(shù)建議是整數(shù)型。

importnumpyasnp

np.random.rand(8)

output[0.559584210.973587610.777532460.280728690.184677940.85755336

0.039760480.08161713]

2、np.random.randn這個函數(shù)返回一個樣本,具有標(biāo)準(zhǔn)正態(tài)分布。

np.random.randn(8)

output[0.55128081.32780895-0.957387560.93710414-2.0854875-0.5100787n0.40982079-1.235186]

3、np.random.randint(low[,high,size])返回隨機(jī)的整數(shù),位于半開區(qū)間[low,high)。

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

output[3387326236]

4、random_integers(low[,high,size])返回隨機(jī)的整數(shù),位于閉區(qū)間[low,high]。

np.random.random_integers(5)

output=4

5、np.random.shuffle(x)類似洗牌,打亂順序;np.random.permutation(x)返回一個隨機(jī)排列.

arr=np.arange(10)

np.random.shuffle(arr)

print(arr)

np.random.permutation(10)

output[1752943608]

array([1,7,4,3,0,9,2,5,8,6])

用random模塊自己構(gòu)造

1、random.randint(low,hight)-返回一個位于[low,hight]之間的整數(shù)。

該函數(shù)接受兩個參數(shù),這兩個參數(shù)必須是整數(shù)(或者小數(shù)位是0的浮點(diǎn)數(shù)),并且第一個參數(shù)必須不大于第二個參數(shù)

importrandom

random.randint(1,10)

random.randint(1.0,10.0)

2、random.random()-不接受參數(shù),返回一個[0.0,1.0)之間的浮點(diǎn)數(shù)

random.random()

3、random.randrange(start,stop,step)-返回以start開始,stop結(jié)束,step為步長的列表中的隨機(jī)整數(shù),同樣,三個參數(shù)均為整數(shù)(或者小數(shù)位為0),若start大于stop時,setp必須為負(fù)數(shù).step不能是0

random.randrange(1,

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論