prjemian / punx

Python Utilities for NeXus HDF5 files
https://prjemian.github.io/punx
5 stars 7 forks source link

getting the value of a scalar dataset #172

Open prjemian opened 2 years ago

prjemian commented 2 years ago

As noted by the APS USAXS, consider this algorithm to access scalar values in HDF5 files:


if dataset.shape == (1, ):  # historical representation of scalar value
    value = dataset[0]
elif  dataset.shape == ():  # scalar representation
    value = dataset.value
else:  # array of some sort
    value = numpy.array(dataset)