appending hdf5 files

Solutions on MaxInterview for appending hdf5 files by the best coders in the world

showing results for - "appending hdf5 files"
Eleonora
21 Jan 2020
1with h5py.File('.\PreprocessedData.h5', 'a') as hf:
2    hf["X_train"].resize((hf["X_train"].shape[0] + X_train_data.shape[0]), axis = 0)
3    hf["X_train"][-X_train_data.shape[0]:] = X_train_data
4
5    hf["X_test"].resize((hf["X_test"].shape[0] + X_test_data.shape[0]), axis = 0)
6    hf["X_test"][-X_test_data.shape[0]:] = X_test_data
7
8    hf["Y_train"].resize((hf["Y_train"].shape[0] + Y_train_data.shape[0]), axis = 0)
9    hf["Y_train"][-Y_train_data.shape[0]:] = Y_train_data
10
11    hf["Y_test"].resize((hf["Y_test"].shape[0] + Y_test_data.shape[0]), axis = 0)
12    hf["Y_test"][-Y_test_data.shape[0]:] = Y_test_data