Modify HDF5 datasets with Julia

Viewed 126

I'm trying to overwrite an existing dataset in a HDF5 file using Julia (version 1.5.3), in particular the HDF5 package. I was looking around for a while to find an answer, but surprisingly I couldn't find anything useful - so here we go: what is the preferred way to modify an existing dataset in an HDF5 file?

1 Answers

HDF5.jl will error if you try to assign a new value into the dataset, but you can overwrite it using the : indexing operator:

# create the dataset if it doesn't already exist
g["my_dataset"] = [1, 2, 3]

# will fail because the dataset already exists
g["my_dataset"] = [4, 5, 6]

# overwrites the existing dataset with the new data
g["my_dataset"] = [7, 8, 9]

Note that the sizes of the new and old datasets must be equal. Otherwise you'll have to delete the existing dataset and recreate it.

Related