efficiently create and fill array.array from C code?
Stefan Behnel
stefan_ml at behnel.de
Sun Jun 13 14:41:09 EDT 2010
Thomas Jollans, 13.06.2010 19:15:
> I'm writing some buffer-centric number-crunching routines in C for
> Python code that uses array.array objects for storing/manipulating data.
> I would like to:
>
> 1. allocate a buffer of a certain size
> 2. fill it
> 3. return it as an array.
Take a look at a) NumPy and b) Cython. You can also use Cython with the
array module, but NumPy is a much more common way to deal with "number
crunching routines", especially multi-dimentional arrays.
Cython interacts with both through the buffer interface, which Stephen
Hansen already mentioned, but it also has support for Python versions that
do not already have it, and it certainly makes the interaction between
Python code and C code really easy. It's also an optimising (mostly) Python
compiler that's used a lot for number crunching code, in case you are not
really into writing the code in C.
Stefan
More information about the Python-list
mailing list