import numpy as np
a = [[0, 0, 0, 255, 255, 255, 0, 0, 0], [0, 0, 0, 255, 255, 255, 0, 0, 0],
    [255, 255, 255, 0, 0, 0, 255, 255, 255]]
a = np.array(a)
a.astype('u1').reshape((3, 3, 3))
import PIL.Image
i = PIL.Image.fromarray(a.astype('u1').reshape((3, 3, 3)), 'RGB')
How to, given a 2D numpy arrayMatrix that contains "triplets" of RGB values generate an image?