close

numpy 是tensorflow中常用來處理數據集的library

假如我們有一個數據集其中有label和data

要怎麼樣將資料集打散並且保持label與data不亂掉呢

這時候我們就會用到以下的程式碼

 

permutation = np.random.permutation(train_label.shape[0])
shuffled_dataset = train_data[permutation, :, :]
shuffled_labels = train_label[permutation]

permutation可以獲得打亂的行號輸出permutation為array([2,1,0])

然後利用numpy array內建的的train_data[permutation,:,:]就可以得到已這個當作排序的數據集了

重點:在一般進行深度學習遇到資料型態有問題時最通用的解決方式就是將資料型態轉為Numpy格式


arrow
arrow

    低階ㄇㄋ 發表在 痞客邦 留言(0) 人氣()