1.3 - Reshaping arrays: Understanding why it is defined as a 3x3x2 array

H​i all, in section 1.3 in the Optional Assignment, ln[13] comments “#This is a 3 by 3 by 2 array”

I don’t understand why this is called a 3x3x2 instead of a 3x2x3. Each array is 3x2 and then there are 3 of them. Could someone please explain how I’m misreading array formating? Which is length, which is height and which is depth?

T​hanks!

Hi, in the example you have:

t_image = np.array([[[ 0.67826139,  0.29380381],
                     [ 0.90714982,  0.52835647],
                     [ 0.4215251 ,  0.45017551]],

                   [[ 0.92814219,  0.96677647],
                    [ 0.85304703,  0.52351845],
                    [ 0.19981397,  0.27417313]],

                   [[ 0.60659855,  0.00533165],
                    [ 0.10820313,  0.49978937],
                    [ 0.34144279,  0.94630077]]])

So starting from the first array, you have 3 elements.

Then if you pick the first of those you have again 3 elements:

[[ 0.67826139,  0.29380381],
 [ 0.90714982,  0.52835647],
 [ 0.4215251 ,  0.45017551]]

And finally if you pick the first element inside that you have 2 elements.

[ 0.67826139,  0.29380381]

That gives you 3 x 3 x 2

I think your question is related to the fact that in the Ex.5 description is mentioned: image – a numpy array of shape (length, height, depth). But the numpy array representing this image has dimensions (depth, height, length).
For example, for the figure from section 1.3, the array will have dimensions (3, 5, 4).

Thanks AlbertoVilla and Zulya.
Zulya, yes this is what is confusing me.
So numpy does (depth, height, length) - I understand now.

As a side note of further confusion for me, where it is said ‘length’ I would have thought ‘width’.

1 Like

I also like “width” more, was glad to help

1 Like