I'm having a problem where, when slicing a float16 NDarray loaded from a HDF5 file with indices provided for the slice, all the numbers in that array when read are NaN.
def read_dataset(group, dataset):
d_m = group["%s" % (dataset)].attrs['d_m']
size = group["%s" % (dataset)].shape
read_start = [abs(d) for d in d_m]
read_end = [s-abs(d) for d, s in zip(d_m, size)]
if len(read_end) == 2:
data = group[dataset][...]
read_data = data[read_start[0]:read_end[0], read_start[1]:read_end[1]]
elif len(read_end) == 3:
data = group[dataset][...]
read_data = data[read_start[0]:read_end[0], read_start[1]:read_end[1], read_start[2]:read_end[2]]
else:
raise NotImplementedError("")
print("Dataset", dataset, "has dtype", read_data.dtype)
print("Data:")
print(read_data) # gives NaNs
print("Original data:")
print(data) # no problem
return read_data
Group is a HDF5 Group object, and both data and read_data are NDarrays. The purpose of the function is to strip out halo points from the results of a CFD simulation-in this specific case, read_start = [5, 5, 5], read_end = [134, 134, 134], and the shape is (139, 139, 139), and it does so without issue for float32 and float64 datasets. The console output for any float16 dataset looks something like the attached images.