[Pyrex] Efficient array creation
Robert Bradshaw
robertwb at math.washington.edu
Sat Jun 28 03:04:08 CEST 2008
On Jun 27, 2008, at 2:15 PM, Brad Schick wrote:
> Is there an efficient way to create python array instances in pyrex
> code? I use python arrays to return data fairly often, but the
> resulting C code is fairly involved.
For a fixed size array, [item1, item2, ...] is about as efficient as
you get. In Cython (and I believe in Pyrex too, though I'm not sure)
the append method is translated into the correct C call, and in
Cython one can do list comprehension as well, e.g. if you have a C
array of ints, then [arr[i] for i from 0 <= i < n] will turn it into
a Python list.
- Robert
More information about the Pyrex
mailing list