# What is the order of elements in an image in python?

I have a set of images which are loaded from an h5 file. I checked their dimensions and I get (209, 64, 64, 3).

read = h5py.File('datasets/train_catvnoncat.h5', 'r')


(209, 64, 64, 3)

it means that there are 209 images but the point that I cannot understand is that, what is (64, 64, 3)?
I have used the following code for plotting:

import matplotlib.pyplot as plt

plt.show()


and I get a colored image which is 64 by 64. before this, I thought for (., ., .) shapes, the second number specifies the number of lines and the third one specifies the number of rows. also the first one specifies the number of the mentioned (row and column) arrays.
My question is that in numpy if you have a three dimensional array, for accessing rows and columns you have to change the second and third entries in the indexing operator; Why this is different in images and rows and columns are arranged differently in images. Shouldn't it be (3, 64, 64)?

• Assuming these are colour images, it seems likely that the 64x64 is row and column index, and the remaining three values are the RGB channels for the image. Sep 21, 2017 at 15:42
• @RHill This is exactly my point. Shouldn't it be (3, 64, 64)? Sep 21, 2017 at 15:49
• @NeilSlater you are telling me this ordering is different from what we have in other containers such as list or tuples? Sep 21, 2017 at 16:24
• @NeilSlater actually I want to change my example, instead of tuples or list think about arrays in numpy or matrices in numpy. whenever we want to access the rows and columns of matrices (actually tensors) with 3-d shape we use second and third entries to access the corresponding elements. Sep 21, 2017 at 16:28

The [64, 64, 3] shape you have found is a common convention to represent a colour image in (x, y, colour_channel) dimensions.