2016-08-26 83 views
0

我有我從一個文件夾轉換附加圖像列表中的熊貓數據幀

samples=[]  
for filename in glob.glob(path + '/*.png'): 
    samples.append(misc.imread(filename)) 

這個名單的樣本追加圖像後創建的樣子

[array([[ 4, 4, 4, ..., 5, 5, 4], 
    [ 5, 5, 5, ..., 6, 6, 5], 
    [ 5, 5, 5, ..., 6, 6, 4], 
    ..., 
    [12, 12, 11, ..., 12, 12, 7], 
    [12, 11, 11, ..., 13, 12, 7], 
    [11, 11, 10, ..., 12, 12, 7]], dtype=uint8), array([[ 4, 4, 4, ..., 7, 7, 6], 
    [ 5, 5, 5, ..., 6, 6, 4], 
    [ 5, 5, 5, ..., 7, 7, 5]], dtype=uint8)] 

它是如何轉換列表圖像的尺寸在Pandas DataFrame中。當我試圖用

df=pd.DataFrame(samples) 

做它給了我一個錯誤

ValueError: Must pass 2-d input 

請Suggest-我會感謝每個幫助

+0

你有2-d陣列的列表,這使得'samples' 3D對象。看看熊貓的面板,這是專門用來保存三維數據。 – Khris

+0

我想僅轉換爲2d數據幀,以便我可以使用isomaps技術 –

+0

然後,您需要將列表中的每個元素放入其自己的數據框中,或者創建一個內部列表作爲單元格中的元素的數據框。 – Khris

回答

0

嘗試添加.reshape(-1),同時附加圖像。

for filename in glob.glob(path + '/*.png'): 
    samples.append(misc.imread(filename).reshape(-1)) 

df = pd.DataFrame.from_records(samples) 

如果你想3D版本,請閱讀 Reshaping a numpy array in python