I know how to get a slice from a Numpy array using the C API this way:
// 'arr' is a 2D Python array, already created
PyObject pyArray = PyArray_FromAny(arr, PyArray_DescrFromType(NPY_FLOAT), 0, 0, NPY_ARRAY_DEFAULT, null);
PyObject slice = PySlice_New(PyLong_FromLong(0), PyLong_FromLong(2), null);
PyObject result = PyObject_GetItem(pyArray, slice);
This basically matches the following Python expression:
arr[0:2]
Now, how can I get a "multi" slice from 'arr'? For instance, how can programmatically write the following expression?
arr[0:2,0:3]
PyObject slice_a = PySlice_New(PyLong_FromLong(0), PyLong_FromLong(2), null);andPyObject slice_b = PySlice_New(PyLong_FromLong(0), PyLong_FromLong(3), null);, then create a tuple likePyObject tuple = PyTuple_Pack(2, slice_a, slice_b)and then callPyObject result = PyObject_GetItem(pyArray, tuple);PyDict_SetItemString(globals, "result", result); PyRun_SimpleStringFlags("print(result, flush=True)", null);(printing code succeeds when my slice is 1D)__getitem__in python(3) has signature__getitem__(self, key)and it is "not allowed"__getitem__(self, key_1, key_2), thus inarray[0:2,0:3]I suspect it is actuallyarray.__getitem__(self,key = (slice(0,2), slice(0,3)))