[SciPy-user] Array indexing in Weave
Christian Kristukat
ckkart at hoc.net
Fri Nov 17 00:10:55 EST 2006
Anand Patil wrote:
> Hi all,
>
> I'm trying to get the hang of Weave. The following:
>
> from numpy import *
> from numpy.random import *
> from scipy import weave
>
> A=zeros((10,10),'int')
> code = """
>
> int i, j;
>
> for(i=0;i<10;i++){
> for(j=0;j<10;j++){
> A(i,j) = i * j;
> }
> }
>
> """
> weave.inline(code,['A'])
>
> causes a mysterious error:
>
> In [4]: run test
> <weave: compiling>
> /Users/anand/.python24_compiled/sc_b84b6757c6b3041e185ca5eff00c331c0.cpp:
> In function 'PyObject* compiled_func(PyObject*, PyObject*)':
> /Users/anand/.python24_compiled/sc_b84b6757c6b3041e185ca5eff00c331c0.cpp:677:
> error: 'A' cannot be used as a function
>
> It looks like it doesn't like the syntax A(i,j) for accessing the
> elements of A, but isn't that how it's done in the examples in the numpy
> book?
>
> Thanks in advance,
> Anand
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
You need anadditional keyword argument:
from scipy.weave import converters
weave.inline(code,['A'],type_converters = converters.blitz)
Christian
More information about the SciPy-User
mailing list