Image2vector implementation vs lecture

In the lecture, I thought the image array had to be flattened such that all the reds, greens and blue values would be listed together, e.g. [r1, r2, r3, g1, g2, g3, b1, b2, b3].

However in the implementation (as well as the passed test using two colors), the flattened array appears to be [r1, g1, r2, g2 …]

1 Like

I think your observation is correct.

Let’s create 3x2x3 ndarray like this.

As you see, the result of flatten (which should be same as our exercise that use reshape) is

array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])

numpy flatten has an option to change the order. Default is β€œC”. If we use β€œF”, which is Fortran format, the result is as follows.

array([ 0, 6, 12, 3, 9, 15, 1, 7, 13, 4, 10, 16, 2, 8, 14, 5, 11, 17])

It starts with the first channel (Red in the figure), but axis is not exactly same as the image provided.