Flags¶
Slicing NumPy arrays allows you to edit rectangular blocks of data.

Here is the code that carves out a red square from the image:
from PIL import Image
import numpy as np
a = np.zeros((300, 500, 3), dtype=np.uint8)
a[100:200, 200:299, 0] = 255
im = Image.fromarray(a)
im.save('area.png')
Hints¶
the slicing contains an interval
from:tofor each dimensionthe smallest
fromvalue is zerothe highest
tovalue is the size of that dimension plus onenegative numbers count from the back
both
fromandtocan be omitted
Challenge¶
Draw the flag of a country of your choice, e.g.:
