I have a h5py
file, which contains information about a dataset. There are n
items inside the dataset and k
keys. For example, for each item I have stored a value for the keys bbox
, number_keypoints
, etc.As the dataset is too huge for me, I want to randomly sample from the dataset and create a smaller h5py
or json
file.
Let's say, I want to sample items [1, 6, 16]
. Then, I want to practically take these indices for all keys (I hope it is clear, what I am trying to do).
Here is, what my idea looks like:
import h5py
with h5py.File(my_file, "r") as f:
arr = [1, 6, 16]
f = {key: value for i, (key, value) in enumerate(f.items()) if i in arr}
Unfortunately, this doesn't work. Can anyone help me here?
question from:
https://stackoverflow.com/questions/65921820/how-to-select-a-subset-of-a-dictionary-by-index 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…