import numpy as np from numpy.lib.format import open_memmap from pathlib import Path path = Path("sensor-readings.npy") mapped = open_memmap(path, mode="w+", dtype=np.float32, shape=(3, 4)) mapped[:] = np.arange(12, dtype=np.float32).reshape(3, 4) mapped[-1, -1] = 99 mapped.flush() readonly = np.load(path, mmap_mode="r") print("mapped type:", type(mapped).__name__) print("readonly type:", type(readonly).__name__) print("mapped shape:", mapped.shape) print("mapped dtype:", mapped.dtype) print("readonly writeable:", readonly.flags.writeable) print("last row:", readonly[-1].tolist()) print("saved value:", float(np.load(path)[-1, -1]))