[Numpy-discussion] Owndata flag

Fabrice Silva silva at lma.cnrs-mrs.fr
Fri Dec 16 05:53:16 EST 2011

Le jeudi 15 décembre 2011 à 18:09 +0100, Gregor Thalhammer a écrit :

> There is an excellent blog entry from Travis Oliphant, that describes
> how to create a ndarray from existing data without copy:
> http://blog.enthought.com/?p=62
> The created array does not actually own the data, but its base
> attribute points to an object, which frees the memory if the numpy
> array gets deallocated. I guess this is the behavior you want to
> achieve. 
> Here is a cython implementation (for a uint8 array)

Even better: the addendum!

Within cython:
cimport numpy
numpy.set_array_base(my_ndarray,  PyCObject_FromVoidPtr(pointer_to_Cobj, some_destructor))

Seems OK.
Any objections about that ?
Fabrice Silva

More information about the NumPy-Discussion mailing list