How is the matrix/array arranged after stretching each image data into one column?

It’s a great question and it has come up before: Here’s a thread which goes through the flattening process in detail. Make sure to also read the later posts there that discuss the difference between the “C” ordering (the default) and the “F” ordering.

The short answer is that the “C” order (the default) gives you all 3 color values for each pixel location together. If you use the “F” order, then you get all the red pixel values, followed by all the green pixel values, followed by the blue. So that method gives you the equivalent of 3 monochrome images back to back. The other high level point is that the algorithm can learn to recognize the patterns in either order, as long as you are consistent and always use the same method. See the thread for concrete demonstrations of this.