Can't remember the canonical way to do this (possibly avoiding the transposes) but this should work:
import numpy as np
M = np.random.random_sample((3, 3))
rgb = np.random.random_sample((5, 4, 3))
slow_result = np.zeros_like(rgb)
for i in range(rgb.shape[0]):
for j in range(rgb.shape[1]):
slow_result[i, j, :] = np.dot(M, rgb[i, j, :])
# faster method
rgb_reshaped = rgb.reshape((rgb.shape[0] * rgb.shape[1], rgb.shape[2]))
result = np.dot(M, rgb_reshaped.T).T.reshape(rgb.shape)
print np.allclose(slow_result, result)
If it's a transformation between standard colorspaces then you should use Scikit Image:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…