I am new to HDF5 format and I am also not hundred percent confident with Mathematica. I have googled to find out examples to deal with HDF5 files in Mathematica but couldn't find one that work out for me. What I would like to do is simply to import a .h5 file, print the dimension of all the subsets, choose one of them and plot it. After

In[1]:= Import["path/to/file.h5"]
Out[1]:= {"/AGB_CO", "/AGB_PY", "/AGE", "/AREA", "/AREA_SI", \
...lots of other subsets...}

which shows all the subsets in the hdf5 file I am stuck. Thanks for any help.

  • $\begingroup$ Without the actual file to work with, I can't give an answer. But when execute that code, it gives the elements in your file. Let's say the first one is elem. Then try test=Import["file.h5",elem1];Dimensions[test] $\endgroup$
    – Jason B.
    Commented Nov 18, 2015 at 10:44
  • $\begingroup$ I get elem1 is not a valid format or element specification. Expecting a \ string, list, or integer. Moreover I may not know which are the subsets in the file before Importing it. What I would need is a script that Import the file, shows all the imported data and plot it. $\endgroup$
    – Manfredo
    Commented Nov 18, 2015 at 10:52
  • $\begingroup$ Edit the question, and copy and paste the output that you get from Import["path/to/file.h5"] $\endgroup$
    – Jason B.
    Commented Nov 18, 2015 at 10:57

3 Answers 3


Without having the data file myself, I can only give a general sort of answer here. But when you look at the documentation under Import and Export, it says

Import["file.h5"] returns a list of strings representing the names of all datasets contained in the file.


Import["file.h5",elem] imports the specified element from an HDF5 file.

So you can try

elemlist = Import["path/to/file.h5"];
importedelemets = Import["path/to/file.h5", # ] &/@ elemlist;
Dimensions /@ importedelemets

Of course, that assumes the first element of the file is a simple list. You may need to play around with it. There may be subelements apparently,

Import["file.h5",{elem,suba,subb,…}] imports a subelement.

  • 1
    $\begingroup$ There is an error in what you have written. I have just played with hdf5 and mma and the doc is not easy to understand. The correct synthax is importedelemets = Import["path/to/file.h5", {"Datasets",#} ] &/@ elemlist; : The elements given by Import["...h5"] are not directly usable as 2nd argument of Import. (the hdf5 file is coming from a Agilent-Keysight oscilloscope). $\endgroup$
    – andre314
    Commented Feb 3, 2016 at 21:21

In M11.1 you can try one of these:

  • Import["path/to/file.h5", "Dimensions"] to get dimensions of all datasets
  • Import["path/to/file.h5", {"Dimensions", "/path/to/dataset"}] to get dimensions of a specific dataset
  • Import["path/to/file.h5", {"Dimensions", n}] to get dimensions of the n-th dataset

This is a significant improvement over previous version of Import because it does not need to load the dataset into memory to get the dimensions.


You can see:


There are some screenshots about compound datatypes, and you could also download the package and use it.

This is version 2.00 (August 2016) of the package that was originally provided as version 1.00 in July 2011.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.