python - How to overwrite array inside h5 file using h5py -


i'm trying overwrite numpy array that's small part of pretty complicated h5 file.

i'm extracting array, changing values, want re-insert array h5 file.

i have no problem extracting array that's nested.

f1 = h5py.file(file_name,'r') x1 = f1['meas/frame1/data'].value f1.close() 

my attempted code looks no success:

f1 = h5py.file(file_name,'r+') dset = f1.create_dataset('meas/frame1/data', data=x1) f1.close() 

as sanity check, executed in matlab using following code, , worked no problems.

h5write(file1, '/meas/frame1/data', x1); 

does have suggestions on how successfully?

askewchan's answer describes way (you cannot create dataset under name exists, can of course modify dataset's data). note, however, dataset must have same shape data (x1) writing it. if want replace dataset other dataset of different shape, first have delete it:

del f1['meas/frame1/data'] dset = f1.create_dataset('meas/frame1/data', data=x1) 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -