[SciPy-User] Problem with passing a 2D Numpy array in the C code by weave.inline
Steven Nien
steven.nien@gmail....
Thu Dec 3 06:03:29 CST 2009
Hello,
Thanks, but it didn't work (with error message).
Below is my code:
from scipy.weave import inline
import numpy
arr = numpy.zeros((2,3), dtype='double')
code = \
"""
arr(1,1) = 1;
"""
inline(code,['arr'], verbose = 1, compiler = 'gcc')
print arr
But what I actually want is something like this:
from scipy.weave import inline
import numpy
arr = numpy.zeros((2,3), dtype='double')
code = \
"""
arr[1][1] = 1;
"""
inline(code,['arr'], verbose = 1, compiler = 'gcc')
print arr
Maybe need to use the type_factories argument in the inline function or
something like this?
Any idea?
Regards,
Steven Nien
2009/12/3 Jose Gomez-Dans <jgomezdans@gmail.com>
> Hi,
>
> 2009/12/3 Steven Nien <steven.nien@gmail.com>
>
> I'm trying to pass a 2 dimensional numpy array into the 'weave.inline' and
>> doing some computation in C.
>> But it seems that the 'weave.inline' will convert a 2d array in python
>> into a 1d array in C.
>>
>> So if I have a MxN array 'arr'
>> I need to access arr[2][3] in C by the following code:
>>
>
> I think weave inline compiles code into C++ and links against the blitz
> libraries, so that numpy arrays are blitz arrays. You can access the element
> in your example as arr(2,3). For internal consumption, I guess that the
> arrays are still chunks of memory.
>
> J
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20091203/04e7be91/attachment.html
More information about the SciPy-User
mailing list