[Numpy-discussion] C extensions to Numpy
christiaan.kok at philips.com
christiaan.kok at philips.com
Wed Mar 12 00:47:02 CST 2003
> Well, in case you (or others) find it useful, I'm including here a little
> library I wrote for accessing general Numeric 2-d arrays (contiguous or
not)
> in an easy manner.
>
> Here's a snippet of a simple (included) example of a function to print an
> integer array:
>
> static PyObject *idisp(PyObject *self, PyObject *args)
> {
> PyArrayObject *array;
> int **arr; // for the data area
> int i,j,cs;
>
> if (!PyArg_ParseTuple(args, "O!",&PyArray_Type,&array ) )
> return NULL;
>
> arr = imatrix_data(array,&cs);
> for (i=0;i<array->dimensions[0];++i) {
> for (j=0;j<cs*array->dimensions[1];j+=cs)
> printf("%5d ",arr[i][j]);
> printf("\n");
> }
> free(arr);
>
> Py_INCREF(Py_None);
> return Py_None;
> }
>
> You get the **arr pointer and you can then manipulate it as a[i][j]
> conveniently. The supplied example file may be enough for many to write
their
> Numpy C extensions without much trouble.
Could someone also give an example of a small C code which has as input a numeric array and returns an other numeric array? My code either coredumps or leaks memory.
wbr
Christiaan Kok
More information about the Numpy-discussion
mailing list