1

I want to create a c extension to python that takes one integer, and two numpy array as argument. How to do that?

Thank you.

This works:

#include "Python.h"
#include "numpy/arrayobject.h"

static PyObject* test4 (PyObject *self, PyObject *args)
{
    int m;
    if (!PyArg_ParseTuple(args, "i", m))
    {
        return NULL;
    }
}

This also works:

#include "Python.h"
#include "numpy/arrayobject.h"

static PyObject* test4 (PyObject *self, PyObject *args)
{
    PyArrayObject *a_array
    PyArrayObject *ja_array
    if (!PyArg_ParseTuple(args, "O!O!", 
                            &PyArray_Type, &a_array,
                            &PyArray_Type, &ja_array))
    {
        return NULL;
    }
}

The following dont work:

#include "Python.h"
#include "numpy/arrayobject.h"

static PyObject* test4 (PyObject *self, PyObject *args)
{
    PyArrayObject *a_array
    PyArrayObject *ja_array
    int m;
    if (!PyArg_ParseTuple(args, "iO!O!", 
                            &m,
                            &PyArray_Type, &a_array,
                            &PyArray_Type, &ja_array))
    {
        return NULL;
    }
}

The error that I get upon compiling is:

error: expression must have integral type
            &a_array
            ^

I can pass the integer into the function as a numpy array... but things should be simpler.

rxu
  • 1,369
  • 1
  • 11
  • 29

0 Answers0