H5 file with images in Python: Want to randomly select without replacement
An elegant way for sampling without replacement is computing a random permutation of the numbers 1..N (numpy.random.permutation) and then using chunks of size M from it.
Storing data in an h5py file is kind of arbitrary. You could use a single higher dimensional data set or a group containing the N two dimensional data sets. It's up to you. I would actually prefer to have the two dimensional data sets separately (gives you more flexibility) and to iterate over it using Group.iteritems.
I have familiarized myself with the basics of H5 in python. What I would like to do now is two things:

Write images (numpy arrays) into an H5 file.
Once that is done, be able to pick out $M$ randomly. 

What is meant here is the following: I would like to write a total of $N=100000$ numpy arrays (images), into one H5 file. Once that is done, then I would like to randomly select say, $M=50$ images from the H5 file at random, and read them. Then, I would like to pick another $M=50$ at random, and read them in as well, etc etc, until I have gone through all $N$ images. (Basically, sample without replacement). 
Is there an elegant way to do this? I am currently experimenting with having each image be stored as a separate key-value pair, but I am not sure if this is the most elegant. 
Another solution is to store the entire volume of $N$ images, and then randomly select from there, but I am not sure that is elegant either, as it requires me to read in the entire block.