Process 100GB+ datasets directly on disk using virtual memory mapping.
`np.memmap` enables reading and writing portions of massive binary arrays stored on disk without loading the entire multi-gigabyte file into physical RAM.
Memory mapping is like using Google Maps: instead of downloading the satellite images for the entire Earth into your phone, your screen only requests the specific street tile you zoom into.
`mode='r'` (read-only), `mode='w+'` (create/overwrite), `mode='r+'` (read/write in place), `mode='c'` (copy-on-write).
arr = np.memmap('data.dat', dtype='float32', mode='r', shape=(5000, 5000))mmap_arr[0] = 5 # Forgot to flush; changes might stay in OS page buffermmap_arr[0] = 5; mmap_arr.flush()Always call `.flush()` to ensure cached memory pages are written back to disk.
Solve the objective below using NumPy vectorized syntax
Create a memmap array `m = np.memmap('test.dat', dtype='int32', mode='w+', shape=(5,))`, set `m[:] = [1, 2, 3, 4, 5]`, and print `m`.
[1 2 3 4 5]