I have about 150,000 images which I want to load in a numpy array of shape [index][y][x][channel]. Currently, I do it like this:
images = numpy.zeros((len(data), 32, 32, 1))
for i, fname in enumerate(data):
img = scipy.ndimage.imread(fname, flatten=False, mode='L')
img = img.reshape((1, img.shape[0], img.shape[1], 1))
for y in range(32):
for x in range(32):
images[i][y][x][0] = img[0][y][x][0]
This works, but I think there must be a better solution than iterating over the elements. I could get rid of the reshaping, but this would still leave the two nested for-loops.
What is the fastest way to achive the same images 4D array, having 150,000 images which need to be loaded into it?