2016-03-24 10 views
1

多次元配列の1次元のサイズが固定されていない場合にHDF5データセットを作成する方法。私は次のおもちゃのコードを試しましたが、私はここでいくつかのポイントを逃しているようです。PythonでHDF5データセットを作成する際に、可変サイズの配列を扱うにはどうすればよいですか?

import numpy as np 

import h5py 


Polyline=h5py.special_dtype(vlen=np.float32) 

f=h5py.File('dataset.hdf5', mode='w') 

var_features=f.create_dataset('var_features', (10,), dtype=Polyline) 

features = np.empty(shape=(10,), dtype=Polyline) 

for i in range(10): 

    a=10+i*2 
    features[i]=np.arange(a).reshape(a/2,2) 

var_features[...]=features 

print features[0].shape 

print var_features[0].shape 

答えて

0

それはただ一つ以上のNone値を持つmaxsize属性を持つデータセットを作成し、非常に簡単です。

このような何か:

import h5py 
import numpy as np 

fff = h5py.File('test1.h5','w') 
fff.create_dataset('test_resize',(100,100),maxshape=(None,None),chunks=(10,10)) 
fff['test_resize'][:] = np.random.random((100,100)) 
fff.flush() 
fff['test_resize'].resize((150,100)) 
fff['test_resize'][100:150,:] = np.ones((50,100)) 
fff.close() 
関連する問題