CAPI: multidimensional array indexing?
Dear experts,
is there a CAPI function for numpy which implements Python's multidimensional indexing? Say, I have a 2darray
PyArrayObject * M;
and an index
int i;
how do I extract the ith row or column M[i,:] respectively M[:,i]?
I am looking for a function which gives again a PyArrayObject * and which is a view to M (no copied data; the result should be another PyArrayObject whose data and strides points to the correct memory portion of M).
I searched the API documentation, Google and mailing lists for quite a long time but didn't find anything. Can you help me?
Thanks, Johann
Probably the easiest way is to emulate what Python is doing in M[i,:] and M[:,i]. You can create the : with PySlice_New(NULL, NULL, NULL), and the i with PyInt_FromLong. Then create a tuple with Py_BuildValue and use PyObject_GetItem to do the slicing.
It is possible to do the same thing directly in C, but as you've found there aren't convenient APIs for this yet.
Cheers, Mark
On Wed, Jul 27, 2011 at 4:37 PM, Johann Bauer jbauernews@web.de wrote:
Dear experts,
is there a CAPI function for numpy which implements Python's multidimensional indexing? Say, I have a 2darray
PyArrayObject * M;
and an index
int i;
how do I extract the ith row or column M[i,:] respectively M[:,i]?
I am looking for a function which gives again a PyArrayObject * and which is a view to M (no copied data; the result should be another PyArrayObject whose data and strides points to the correct memory portion of M).
I searched the API documentation, Google and mailing lists for quite a long time but didn't find anything. Can you help me?
Thanks, Johann _______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpydiscussion
Cool!
But I'm having trouble implementing this, could you provide an example on how exactly to do this? I'm not sure how to create the appropriate tuple and how to use it with PyObject_GetItem given an PyArrayObject, unless I'm misunderstood.
Much appreciated,
Matthew
 View this message in context: http://numpydiscussion.10968.n7.nabble.com/CAPImultidimensionalarrayind... Sent from the Numpydiscussion mailing list archive at Nabble.com.
participants (3)

Johann Bauer

Mark Wiebe

mpc