Answer the question
In order to leave comments, you need to log in
How to resize numpy.memmap without copying?
Code works but changes are not saved
def test_resize_inplace():
fA = np.memmap('A_r.npy', dtype='uint8', mode='w+', shape=(3,12))
print "fA"
print fA
fA[2][0] = 42
# resize by creating new memmap
new_fA = np.memmap('A_r.npy', mode='r+', dtype='uint8', shape=(20,12))
print 'fA'
print fA
print 'new_fA'
print new_fA
print new_fA
def resize_memmap(fm,sz,tp):
fm.flush()
print fm.filename
new_fm = np.memmap(fm.filename, mode='r+', dtype= tp, shape=sz)
return new_fm
def test_resize_inplace():
fA = np.memmap('A_r.npy', dtype='uint8', mode='w+', shape=(3,12))
print "fA"
print fA
fA[2][0] = 42
sz= (20,12)
tp= 'uint8'
new_fA= resize_memmap(fA,sz,type)
new_fA[9][9]= 111
print 'fA'
print fA
print 'new_fA'
print new_fA
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question