I have an array containing the RGB values of all the pixels in the image. Suppose a 4x4 image has a size of 48, where the first 16 values are red values, the next 16 are green and the last 16 are blue:
[r0, r1, ..., r15, g0, g1, ..., g15, b0, b1, ..., b14, b15]
Now I want to convert this array to a 4x4 matrix with depth 3 in this form:
[[[r0, g0, b0], ..., [r3, g3, b3]],
...
[[r12, g12, b12], ..., [r15, g15, b15]]]
To do this, I do reshape+ transpose+ reshape:
import matplotlib.pyplot as plt
N = 4
numpy.random.seed(0)
rrggbb = numpy.random.randint(0, 255, size=N*N*3, dtype='uint8')
imgmatrix = rrggbb.reshape((3, -1)).transpose().reshape((N, N, 3))
plt.imshow(imgmatrix)
plt.show()

Is there a more efficient / short way to do this? (i.e.: with less transform / transpose)