2017-10-13 52 views
0

例如,我希望有兩個數據集,一個是Input,另一種是Output如何在HDF5中製作多維數據集?

Input的數據和Output是多變暗。

enter image description here

但我在h5pyinput_nodeoutput_node注意是固定的。

Input = f.create_dataset('Input', (3,input_node),dtype='float', chunks=True) 
Output = f.create_dataset('Output', (3,output_node),dtype='float', chunks=True) 

hdf5不能處理這個問題,這個代碼可以證明這一點

import h5py 

X = [[1,2,3,4],[1,2],[1,2,3,4,5,6]] 

with h5py.File('myfile.hdf5', "w") as ofile: 
    ofile.create_dataset("X", data=X) 

TypeError: Object dtype dtype('O') has no native HDF5 equivalent

那麼如何在h5py多變暗數據集?

回答

0

我不完全按照您的{...}表示。在Python中,它們用於字典和集合。 []用於列表,()用於元組。數組形狀表示爲一個元組。

反正,您的代碼產生

In [68]: X 
Out[68]: 
array([ list([0.6503719194043309, 0.8703218883225239, -1.4139639093161405, 2.3288987644271835, -1.7957516518177206]), 
     list([-0.1781710442823114, 0.9591992379396287, -0.6319292685053243]), 
     list([0.7104492662861611, -0.8951817329357393, -0.8925882332063567, 1.5587934871464815]), 
     list([-1.2384976614455354, 0.9044140291496179, 1.1277220227448401]), 
     list([1.1386910680393805, -0.1775792543137636, 1.0567836199711476]), 
     list([2.7535019220459707, 0.29518918092088386, -0.32166742909305196, 1.5269788560083497, 0.29633276686886767]), 
     list([1.6397535315116918, -0.8839570613086122, -0.4491121599234047, -2.4461439611764333, -0.6884616200199412, -1.1920165045444608]), 
     list([1.3240629024597295, 1.170019287452736, 0.5999977019629572, -0.38338543090263366, 0.6030856099472732]), 
     list([-0.013529997305716175, -0.7093551284624415, -1.8611980839518099, 0.9165791506693297]), 
     list([2.384081118320432, -0.6158201308053464, 0.8802896893269192, -0.7636283160361232])], dtype=object) 
In [69]: y 
Out[69]: array([1, 1, 0, 0, 0, 1, 1, 0, 1, 0]) 

y是一個簡單的陣列。 h5py應該沒有問題。

X是對象D型細胞陣列,含有不同大小

In [72]: [len(l) for l in X] 
Out[72]: [5, 3, 4, 3, 3, 5, 6, 5, 4, 4] 

h5py不能保存那種陣列的列表。充其量,您可以將每個元素寫入不同的dataset。它將每個都保存爲一個數組。

.... 
    for i, item in enumerate(X): 
     ofile.create_dataset('name%s'%i, data=item) 
+0

如果將數據保存在'hdf5'中的不同數據集中,那麼當使用這個文件作爲神經網絡的輸入時會導致問題 – partida