I have an HDF5 dataset which I read as a numpy array:
my_file = h5py.File(h5filename, 'r')
file_image = my_file['/image']
and a list of indices called in
.
I want to split the image
dataset into two separate np.array
s: one containing images corresponding to the in
indices, and the other containing images whose indices are not in in
. The order of images is very important - I want to split the dataset such that the original order of the images is preserved within each subset. How can I achieve this?
I tried the following:
labeled_image_dataset = list(file_image[in])
However, h5py gave me an error saying that the indices must be in increasing order. I can't change the order of indices, since I need the images to stay in their original order.
My code:
my_file = h5py.File(h5filename, 'r')
file_image = my_file['/imagePatches']
li = dataframe["label"]
temporary_list = file_image
# select images whose indices exist in "in"
labeled_dataset = list(temporary_list[in])
# select images whose indices don't exist in "in"
unlabeled_dataset = np.delete(temporary_list, in, 0)