Search code examples
pythonarrayscnumpypython-c-api

What is the corresponding C-api name of the following numpy function in Python


  • I wanna write a C extension lib for Python, aiming to replace Python code with C.
  • and the Python codes has several lines like below:
import numpy as np
a = np.array([1,3,12,0.43,234,-3,-4])
b = a[[1,3,5]]
print(b)

# array([ 3.  ,  0.43, -3.  ])

  • Different from an int as the index of a numpy array, this example treats an array as an index.

  • I am confused that getting the designated indexes of a given numpy array, what is the corresponding C-API name?

  • the NUMPY C-API files is in numpy c-api

  • Thanks very much.


Solution

    • Finally I find this numpy C func, of which the name is PyArray_Choose.
    • The complete func definition is PyObject *PyArray_Choose(PyArrayObject *self, PyObject *op, PyArrayObject *ret, NPY_CLIPMODE clipmode)
    • numpy choose