representing list of tuples as 2d array in python -


Say I have a list of Tuples with RGB information of each pixel in an image from which left to right, from top to bottom.

[(1,2,3), (2,3,4), (1,2,4), (9,2,1), (1,1,1) , (3,4,5)]

Already know the width and height of the image, is there any way that I can represent the image using the list list Am I For example, suppose that the above list of the Tuples represents the 2x3 image, the image [1] [2] me the RGBTupple (3,4, 5) should give .

use the step argument (or):

  & gt; & Gt; & Gt; Width = 2> gt; & Gt; & Gt; Pixel = [[1,2,3], (2,3,4), (1,2,4), (9,2,1), (1,1,1), (3, 4, 5) ] & Gt; & Gt; & Gt; Image = [pixels [x: x + width] range for x (0, lenan (pixels), width)]> gt; & Gt; & Gt; Image [(1, 2, 3), (2, 3, 4)], [(1, 2, 4), (9, 2, 1)], [(1, 1, 1), (3, 4 , 5)]]  

This increases the value of x with the value of step , instead of the default, which is 1. If you have Java , It is similar to:

 for  (int x = 0; x  x = x + phase)  

Comments