[SciPy-user] Array indexing in Weave

Anand Patil anand at soe.ucsc.edu
Thu Nov 16 23:08:22 CST 2006


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


More information about the SciPy-user mailing list