It is recommended to load large files into memory maps. Memory-mapped files only load a small part of large files. NumPy memory maps are array-like. In this example, we will generate an image of colored squares and load it into a memory map.
If necessary, install matplotlib. The See also section has a reference to the corresponding recipe.
We will begin by initializing arrays:
Initialize the arrays:
img = np.zeros((N, N), np.uint8) NSQUARES = 30 ...