[Numpy-discussion] Altering/initializing NumPy array in C

Nathaniel Smith njs at pobox.com
Wed Jan 1 15:04:52 EST 2014

On 1 Jan 2014 13:57, "Bart Baker" <bartbkr at gmail.com> wrote:
> Hello,
> I'm having issues with performing operations on an array in C and
> passing it back to Python. The array values seem to become unitialized
> upon being passed back to Python. My first attempt involved initializing
> the array in C as so:
> double a_fin[max_mth];
> where max_mth is an int.

You're stack-allocating your array, so the memory is getting recycled for
other uses as soon as your C function returns. You should malloc it instead
(but you don't have to worry about free'ing it, numpy will do that when the
array object is deconstructed). Any C reference will fill you in on the
details of stack versus malloc allocation.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140101/6bb5abcc/attachment.html>

More information about the NumPy-Discussion mailing list