Numeric Python and C
John Hunter
jdhunter at ace.bsd.uchicago.edu
Wed Jan 14 23:19:14 EST 2004
>>>>> "Ognen" == Ognen Duzlevski <maketo at norge.freeshell.org> writes:
Ognen> Hi, can someone explain how to change a value within an
Ognen> array from a C function?
Warning: I am not a Numeric C API guru.
For 1D arrays I use the following macro
// get x[i] from a 1d array of type xtype
#define get1d(x,i,xtype) \
*(xtype *)(x->data+i*x->strides[0])
You can assign to the return value of this, as in
count = 0;
while ((row = mysql_fetch_row(res)) != NULL) {
get1d(p,count,float) = atof(row[0]);
get1d(v,count,int) = atoi(row[1]);
++count;
}
where p and v are 1D numeric arrays.
You'll have to do a bit more work for 2D arrays, but this may speed
you on your way....
JDH
More information about the Python-list
mailing list