Exercise 1: Create numpy array and draw rgb color objects
import numpy as np
import matplotlib.pyplot as plt
create data array 2x2 as pixel position and 1x3 as rgb color data
width, height = 200, 200
data = np.zeros((height, width, 3), dtype=np.uint8)
draw blue cross
x = np.arange(width)
x_1 = np.arange(width)
x_2 = np.arange(width-1,-1,-1)
y = np.arange(height)
data[x_1,y] = [0,0,255]
data[x_2,y] = [0,0,255]
draw a square
lower = 55
upper = 75
data[lower:upper,lower:upper] = [0,255,0]
create a mask of a circle using indexing np.newaxis adds another dimension we create a row and column vector and fill it using the condition
x_center = 100
y_center = 100
radius = 10
mask = (x[np.newaxis,:]-x_center)**2 + (y[:,np.newaxis]-y_center)**2 < radius**2
data[mask] = [255,0,0]
# plot image
plt.figure(figsize=(4.,4.),dpi=100,facecolor='lightgrey')
plt.imshow(data)
plt.show()