import numpy as np from numpy.lib.format import open_memmap shape = (1, 20, 600, 2160) dtype = np.float32 # Open a memory mapped numpy formatted file for a temporary variable data = open_memmap('temp.npy', dtype = dtype, mode = 'w+', shape = shape) data[:] = np.random.rand(*shape) data.flush() # force write disk test = np.array(data) # copy to memory for checking below print(data) del data # release memory mapped file # load temporary variable as memory mappe filed (no data is loaded into memory) data2 = np.load('temp.npy', mmap_mode='r') np.testing.assert_array_equal(test, data2) # read and compare as necessary # create a second output file, also memory mapped and store result of computation data3 = open_memmap('out.npy', dtype = dtype, mode = 'w+', shape = shape) data3[:] = data2*40. + data2**4 del data3 # flushes to disk # load using memory map (no data is loaded yet) data4 = np.load('out.npy') # assert that contents match computed values above np.testing.assert_array_equal((data2*40. + data2**4), data4)