Why don't means of color channels average to equal flattened array mean
You just understood numpy wrong (God bless those who understood it right). The correct code should have been:

trainImgsArr = np.random.rand(17611, 224, 224, 3)
grandMean = np.mean(trainImgsArr)
meanByChannel = []
for i in range(0, 3):
    avg = np.mean(trainImgsArr[:, :, :, i]
    meanByChannel.append(avg)


Basically I am doing splicing of the array,taking all pixels of a colour channel from all images and averaging them. Whereas you did something else entirely (your results are not reproducible). Axes (0, 1, 2) does not mean the colour channels it only means the index you are referring to and performing the required operation.



Ignore the convolution part but check the subscripts of h_n-1 you can access the those positions by varying the last argument in trainImgsArr.shape.