I am running a simulation from which I need to record some small numpy arrays every cycle. My current solution is to load, write then save as follows:
existing_d
I have found a good working solution using the h5py library. Performance is far better as there is no reading data and I have cut down on the number of nump array append operations. A short example:
with h5py.File("logfile_name", "a") as f:
ds = f.create_dataset("weights", shape=(3,2,100000), maxshape=(3, 2, None))
ds[:,:,cycle_num] = weight_matrix
I am not sure if the numpy style slicing means the matrix gets copied but there is a write_direct(source, source_sel=None, dest_sel=None)
function to avoid this happening which could be useful for larger matrices.