3

How to create a HDF5 dataset when size of one dimension of a multidimensional array is not fixed. I tried the following toy code, but it seems that I am missing some point here.

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

1 Answer 1

1

It's quite simple, just create dataset with maxsize attribute with one or more None values.

Something like this:

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.