numpy.memmap from numpy operations
Let me try to answer the first part of your question. Loading a result into a memmap datastore.
Note I am going to assume that there is a memmap file already on disk - it will be the input file. Called MemmapInput, created as follows:
fpInput = np.memmap('MemmapInput', dtype='bool', mode='w+', shape=(3,4))del fpInputfpOutput = np.memmap('MemmapOutput', dtype='bool', mode='w+', shape=(3,4))del fpOutput
In your case the output file might not be present, but per the docs:'r+' Open existing file for reading and writing.
‘w+’ Create or overwrite existing file for reading and writing.
So the first time you create a memmap file it must be with a 'w+', thereafter to modify/overwrite the file, use 'r+', Readonly copies can be obtained with 'r'. See http://docs.scipy.org/doc/numpy/reference/generated/numpy.memmap.html for more info.
Now we will read in this file and perform some operations on it. The main point is to load a result into a memamp file, the memmap file must first be created and attached to a file.
fpInput = np.memmap('MemmapInput', dtype='bool', mode='r', shape=(3,4))fpOutput = np.memmap('MemmapOutput', dtype='bool', mode='r+', shape=(3,4))
Do whatever you want with the fpOutput memmap file e.g.:
i,j = numpy.nonzero(fpInput==True)for indexI in i: for indexJ in j: fpOutput[indexI-1,indexJ] = True fpOutput[indexI, indexJ-1] = True fpOutput[indexI+1, indexJ] = True fpOutput[indexI, indexJ+1] = True