Hi Marcio,

> Sorry for the basic question, but I want to read a 32-bit
> floating-point, 1000X2048X2048 dataset in python. I want to specify
> the dimensions just like the hdfview utility does when we use "open
> as".
>
> How I do that in python? I tried the following code, but it results in
> a segmentation fault:

It's actually much simpler than the code you posted; for example, to
open the file and access the dataset (both Py2 and Py3):

f = h5py.File("tomo.h5")
dset = f["images"]

To read a subset of the data, use the normal Python-style slicing access:

one_data_point = dset[0, 0, 0]   # Load a single element from our 3D dataset
example_slice = dset[0, 0:10, 0:20]  # 200-element slice

Writing uses the same syntax:

dset[0,0,0] = 42   # Update one element

You can find additional documentation and examples at h5py.org.

If you don't mind my asking, how did you come up with the code you
posted?  It uses h5py's C-style low-level interface, which is
perfectly fine but (as you saw) challenging for newcomers.

Andrew

_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org

Reply via email to