[Numpy-discussion] documentation suggestion

Neal Becker ndbecker2@gmail....
Sat Apr 11 10:30:32 CDT 2009

numpy.ndarray says:

buffer : object exposing buffer interface, optional
Used to fill the array with data.

I found this misleading.  It isn't just used to _fill_ the array - it is the 
actual storage for the array.  If set to an object exporting the buffer 
interface, any updates to the ndarray will change the value of this object.

As an example:

from numpy import *
import eos

import mmap
import os
fd = os.open ('test.dat', os.O_RDWR|os.O_CREAT)
size = 128
os.ftruncate (fd, size)
m = mmap.mmap (fd, size, prot=mmap.PROT_READ|mmap.PROT_WRITE, 

u = ndarray (shape=(size,), dtype=uint8, buffer=m)
u[:] = 24

mmap exports buffer interface (Also not mentioned in the documentation for 
mmap!).  Updating the value of u (last line above) will change the file on 

More information about the Numpy-discussion mailing list