简体   繁体   English

如何在Numpy C API中使用PyArray_SearchSorted

[英]How to use PyArray_SearchSorted in Numpy C API

In a C extension, I am accessing two arrays passed to the function: 在C扩展中,我正在访问传递给函数的两个数组:

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);

and I then want to use PyArray_SearchSorted with these two arrays - I am currently doing: 然后我想对这两个数组使用PyArray_SearchSorted我目前正在做:

PyObject *ix_array = PyArray_SearchSorted(xw_array, x1_array);

But this leads to the following error: 但这会导致以下错误:

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);
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                   ^

What is the correct way to use PyArray_SearchSorted ? 使用PyArray_SearchSorted的正确方法是什么? What are the four arguments required? 需要四个参数? The documentation only mentions two. 文档仅提及两个。

The full declaration of PyArray_SearchSorted is here : PyArray_SearchSorted的完整声明在这里

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

You need to provide a side and a perm arguments. 您需要提供一个side和一个perm参数。 The defaults being NPY_SEARCHLEFT and NULL . 默认NPY_SEARCHLEFTNULL So the following should work: 因此,以下应该工作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM