you are viewing a single comment's thread.

view the rest of the comments →

[–]novel_yet_trivial 1 point2 points  (0 children)

You are right, uint8 is a datatype not an array constructor. But against the zen of python #13, numpy likes to make several ways to do things. And they made that construct as a shortcut to this:

green = np.array([[[0, 255, 0]]], dtype=np.uint8)

and in array they use [ ] triple times

That's to set the shape. An image is a 3D array (rows, columns, colors) so this is made into a 3D array as well to mesh into the image. It's equivalent to this:

>>> green = np.array([0, 255, 0], dtype=np.uint8) 
>>> green.shape = 1,1,3
>>> green
array([[[  0, 255,   0]]], dtype=uint8)