Using numpy array in C code ?

Hello ! I am trying to interface some python code using numpy array with some C code. I have tried out this: - - - - - - - - Python code - - - - - - - - import numpy a = numpy.array([1.4, 2.4, 3.6], dtype=float) my_c_method(a) # call to the C code - - - - - - - - C code - - - - - - - - - - - - #include <Python.h> static PyObject * my_c_method(PyObject *self, PyObject *args) { double * points; points = malloc(sizeof(double)*3); //points = PyTuple_GET_ITEM(args, 3); // doesn't work PyArg_ParseTuple(args, "O&", points); // doesn't work either... printf("points[0] = %f \n",points[0]); // I want this to print points[0] = 1.4 } - - - - - - - - - - - - - - - - - - - - - - - - - - but it doesn't work... Does anyone knows how to use numpy array in some C code? Thanks a lot, Marc

Hi, Fri, 01 Jul 2011 16:45:47 +0200, Marc Labadens wrote:
I am trying to interface some python code using numpy array with some C code.
You can read: http://docs.scipy.org/doc/numpy/user/c-info.how-to-extend.html#writing-an-ex... However, using Cython often saves you from writing boilerplate: http://cython.org/

static PyObject * my_c_method(PyObject *self, PyObject *args) { PyArrayObject *array; double *points; PyArg_ParseTuple(args, "O", &array); points=(double*)array->data printf("points[0] = %f \n",points[0]); } It is should be like that. 2011/7/1 Pauli Virtanen <pav@iki.fi>
Hi,
Fri, 01 Jul 2011 16:45:47 +0200, Marc Labadens wrote:
I am trying to interface some python code using numpy array with some C code.
You can read:
http://docs.scipy.org/doc/numpy/user/c-info.how-to-extend.html#writing-an-ex...
However, using Cython often saves you from writing boilerplate:
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (3)
-
Marc Labadens
-
Pauli Virtanen
-
刘振海