[Numpy-discussion] buffer arg to ndarray

Robert Kern robert.kern at gmail.com
Fri Sep 17 14:00:02 EDT 2010


On Fri, Sep 17, 2010 at 12:42, Neal Becker <ndbecker2 at gmail.com> wrote:
> np.ndarray description says:
>  buffer : object exposing buffer interface
>
> It's nice that it works with mmap:
>
> b = mmap.mmap (...)
> u = np.ndarray (buffer=b ...)
>
> but you wouldn't know it from the above description.
>
> It doesn't look to me that the object returned by mmap exposes the buffer
> interface, does it?

The buffer interface is a C thing. You don't see Python-level methods.
The cheapest way to test if an object can be made into a buffer is to
try it:

In [22]: m = mmap.mmap(f.fileno(), 0)

In [23]: buffer(m)
Out[23]: <read-only buffer for 0x52652c0, size -1, offset 0 at 0x5265380>

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list