How to systematically get data from DataFolder.Samples?

I am working with AT&T face dataset. There are 40 folders each containing 10 images of a person.
I can easily get an image of random class by using:

d = datasets.ImageFolder('./data/')
data = random.choice(d.samples)
label = data[1]

Now I need to pair this image with an (i)th sample image of another class, (say 34th) , but on trying to access a particular image from samples does not work. I know we can randomly iterate through sample and check if desired class image is found but that method seems inefficient.

So, is there a way to access an image of a particular class manually rather than randomly choosing images ?

If you know your target class in advance you could try the following:

target = 1
data = random.choice([d.samples[i] for i, s in enumerate(d.samples) if s[1]==target])

@ptrblck I get the following error when using this exact code in __getitem__ function

    img2 = np.random.choice([self.root.samples[i] for i,sample in enumerate(self.root.samples) if sample[1]==data[1]])
  File "mtrand.pyx", line 1122, in mtrand.RandomState.choice
ValueError: a must be 1-dimensional