[Numpy-discussion] Extending C with Python
chris.barker at noaa.gov
Wed Jan 31 17:58:34 EST 2018
I'm guessing you could use Cython to make this easier. It's usually used
for calling C from Python, but can do the sandwich in both directions...
Just a thought -- it will help with some of that boilerplate code...
On Tue, Jan 30, 2018 at 10:57 PM, Jialin Liu <jalnliu at lbl.gov> wrote:
> Amazing! It works! Thank you Robert.
> I've been stuck with this many days.
> On Tue, Jan 30, 2018 at 10:52 PM, Robert Kern <robert.kern at gmail.com>
>> On Wed, Jan 31, 2018 at 3:25 PM, Jialin Liu <jalnliu at lbl.gov> wrote:
>>> I'm extending C with python (which is opposite way of what people
>>> usually do, extending python with C), I'm currently stuck in passing a C
>>> array to python layer, could anyone plz advise?
>>> I have a C buffer in my C code and want to pass it to a python function.
>>> In the C code, I have:
>>> npy_intp dims ;
>>>> dims = 10;
>>>> dims = 20;
>>>> npy_intp m=2;
>>>> PyObject * py_dims = PyArray_SimpleNewFromData(1, &m, NPY_INT16 ,(void
>>>> *)dims ); // I also tried NPY_INT
>>>> PyObject_CallMethod(pInstance, method_name, "O", py_dims);
>>> In the Python code, I want to just print that array:
>>> def f(self, dims):
>>> print ("np array:%d,%d"%(dims,dims))
>>> But it only prints the first number correctly, i.e., dims. The second
>>> number is always 0.
>> The correct typecode would be NPY_INTP.
>> Robert Kern
>> NumPy-Discussion mailing list
>> NumPy-Discussion at python.org
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion