I made a copy of the first perceptron(ai) in python which use a 20x20 matrix with ones and zeros as input(1=white,0=black). I made 4 image-matrix for it, but it took me half an hour to make them. the ai should distinguish rectangles and circles made from 1s on the image-matrix, so just making random choices won't work.
I tried to make some matrix by hand. it is to slow.
I am assuming that you are trying to generate 20x20 images of circles and rectangles.
Use the OpenCV drawing tools for this purpose. The tutorial can be found here.
I coded this and checked the runtime to be 0.05 s at max for generating 50 samples of each circle and rectangle.
I have documented the code in the comments within it.
NOTE
np.ndarrayincircle_sampleandrect_sampleof size20X20. You can save these images if you want to.cv.FILLEDvalue - it is essentially passing -1 to thethicknessparameter in the drawing function in OpenCV which means "fill the shape". For positive values it will draw a contour of given thickness.