[Pyrex] Re: experiences with numpy array import/export in pyrex

Robert Kern robert.kern at gmail.com
Thu May 4 05:44:54 CEST 2006

Chris Bartels wrote:
> Hi,
> I was curious if there are people who have tried numpy/pyrex in such a
> way that they could dynamically export arrays into python.
> What I had in mind was a pyrex function which takes a number of numpy
> arrays as input (images of a video sequence). Then manipulate the array
> data (fast) by use of a pointer to the raw array data. And output a
> number of newly allocated arrays (filled and allocated in C of course,
> but returning python numpy objects).
> This means creating new numpy arrays and associated buffers by use of
> malloc and then exporting these into numpy python arrays.. quite
> difficult...

Never malloc the arrays yourself. Instead create arrays either using the
Python-level functions (specifically, numpy.empty()) or use PyArray_SimpleNew on
the C level. Then use the data pointer to fill the array.

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 Pyrex mailing list