2014-03-05 72 views
2

在C擴展,我訪問兩個數組傳遞給函數:如何使用PyArray_SearchSorted在numpy的C API

PyObject *xw_array = PyArray_FROM_OTF(xw_obj, NPY_DOUBLE, NPY_IN_ARRAY); 
PyObject *x1_array = PyArray_FROM_OTF(x1_obj, NPY_DOUBLE, NPY_IN_ARRAY); 

,然後我想用PyArray_SearchSorted與這兩個陣列 - 我目前做的:

PyObject *ix_array = PyArray_SearchSorted(xw_array, x1_array); 

但是這會導致以下錯誤:

propagate_pure.c:123:138: error: too few arguments to function call, expected 4, have 2 
PyObject *ix_array = (*(PyObject * (*)(PyArrayObject *, PyObject *, NPY_SEARCHSIDE, PyObject *)) PyArray_API[131])(xw_array, x1_array); 
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     ^

什麼是正確的方法要使用PyArray_SearchSorted?什麼是需要的四個參數? documentation只提到了兩個。

回答

1

PyArray_SearchSorted的完整聲明是here

NPY_NO_EXPORT PyObject * 
PyArray_SearchSorted(PyArrayObject *op1, PyObject *op2, 
        NPY_SEARCHSIDE side, PyObject *perm) 

您需要提供一個sideperm參數。默認值爲NPY_SEARCHLEFTNULL。所以下面應該工作:

PyObject *ix_array = PyArray_SearchSorted(xw_array, x1_array, 
              NPY_SEARCHLEFT, NULL);