Using numpy.memmap you create arrays directly mapped to a file:
import numpy a = numpy.memmap('test.mymemmap', dtype='float32', mode='w+', shape=(200000,1000))
You can think of it as a regular array: a + = 1000.
You can even assign more arrays to the same file, if necessary, and manage it from mutual sources. But I have some tricky things. To open a full array, you first need to "close" the previous one using del :
del ab = numpy.memmap('test.mymemmap', dtype='float32', mode='r+', shape=(200000,1000))
But opening only some part of the array allows for simultaneous control:
b = numpy.memmap('test.mymemmap', dtype='float32', mode='r+', shape=(2,1000)) b[1,5] = 123456. print a[1,5]
Fine! a was changed along with b . And the changes are already written to disk.
Another important thing worth commenting is offset . Suppose you want to take not the first 2 lines in b , but the lines 150000 and 150001.
b = numpy.memmap('test.mymemmap', dtype='float32', mode='r+', shape=(2,1000), offset=150000*1000*32/8) b[1,2] = 999999. print a[150001,2] #999999.0
Now you can receive and update any part of the array in simultaneous operations. Notice the byte size going into the offset calculation. So, for "float64" this example would be 150,000 * 1000 * 64/8.
Other links: