I can't figure out the command to Export an HDF5 file from Mathematica that includes both an Attribute and a DataFormat. I can do one or the other, but not both.

Related questions:

How to export attributes or annotations to an HDF5 file?

How can I export to HDF5 with a specific Datatype ("DataFormat")


Ok, after trying a few more things, the following works:

Export["test.h5", {"Datasets" -> {"/m1" -> {{1, 2}, {2, 3}}, "/m2" -> {{10, 
11}, {12, 13}}}, "DataFormat" -> {"UnsignedInteger16", "UnsignedInteger8"}, 
"Attributes" -> {"m1" -> {"m1Attribute" -> "testAttribute"}}}, "Rules"]

Then Import["test.h5", "DataFormat"] and Import["test.h5", "Attributes"] give <|"/m1" -> "UnsignedInteger16", "/m2" -> "UnsignedInteger8"|> and <|"/" -> <||>, "/m1" -> <|"m1Attribute" -> {"testAttribute"}|>, "/m2" -> <||>|>, respectively.

  • 1
    $\begingroup$ One possible issue here is that currently export of group attributes does not work correctly. It does not affect your example, though. $\endgroup$
    – rafalc
    Dec 12 '17 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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