Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an array slice using the NumPy C API?

I want to slice through a 1D NumPy from within a C extension. I see all sorts of helper functions in the C API for creating fresh arrays, reshaping, indexing particular values, etc.. But I don't see anything like PyArray_Slice1D(array, start, stop, step). Does such a thing exist?

like image 738
Alex Rubinsteyn Avatar asked Sep 20 '13 03:09

Alex Rubinsteyn


1 Answers

You can use Python API: create a slice object by PySlice_New() and then call PyObject_GetItem():

PyObject* PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
PyObject* PyObject_GetItem(PyObject *o, PyObject *key)
like image 52
HYRY Avatar answered Nov 19 '22 05:11

HYRY