Numeric Python and C
Ognen Duzlevski
maketo at norge.freeshell.org
Wed Jan 14 14:17:55 EST 2004
Hi,
can someone explain how to change a value within an array from a C function?
For example, I have the following array:
scoremat = zeros((10,10))
and the following C function:
PyObject *DynAlign(PyObject *self, PyObject *args)
{
PyArrayObject *p;
int ok;
/* get the array */
ok = PyArg_ParseTuple(args,"O!", &PyArray_Type, &p);
/* this gets a value p[5][5] */
v55 = *(double *)p->data + 5*p->strides[0] + 5*p->strides[1]);
}
How to I change the value at p[5][5] and retain it in the same array after function exit?
So, from Python I might have:
from Numeric import *
scoremat = zeros((10,10))
DynAlign(scoremat)
print scoremat[5][5]
Thank you,
Ognen
More information about the Python-list
mailing list