[Cython] how to initialize my c array in a quick way?
Greg Ewing
greg.ewing at canterbury.ac.nz
Mon Nov 10 05:38:41 CET 2008
jay wrote:
> I want declare an array with a shape at the beginning of program,then in my
> function i will assign value to it by calculation.
> Is there a good way to do it?
You can do
a[0], a[1], a[2], a[3], a[4] = 1, 3, 28, 5, 3
which will get turned into a series of assignments.
Ideally, what you *should* be able to do is
a[:] = 1, 3, 28, 5, 3
but unless Cython has grown a feature I don't know about,
that will only work if a is a Python sequence (or possibly
a numpy array, although I'm not sure how efficient it will
be in that case).
--
Greg
More information about the Cython-dev
mailing list