[Pyrex] getting data pointer to numpy object

Brian Blais bblais at bryant.edu
Tue Mar 28 22:05:25 CEST 2006


Hello,

Is there an easy way to get the data pointer to a numpy object which is *not* passed 
as a parameter?  For example, I know I can do:

#---------------
cdef extern from "numpy/arrayobject.h":

   struct PyArray_Descr:
     int type_num, elsize
     char type

   ctypedef class numpy.ArrayType [object PyArrayObject]:
     cdef char *data
     cdef int nd
     cdef int *dimensions, *strides
     cdef object base
     cdef PyArray_Descr *descr
     cdef int flags

def test1(ArrayType w):  # pass a numpy object

     cdef double *w_p

     # get the pointers
     w_p=<double *>w.data
#---------------

...but I would like to do something like...

#-------------------------------
def test2(d):  # pass a python dict

     w=d['w']   # get the numpy object

     cdef double *w_p

     # get the pointers
     w_p=<double *>w.data
#-------------------------------


Is there a way to do this?



			thanks,


				Brian Blais


-- 
-----------------

             bblais at bryant.edu
             http://web.bryant.edu/~bblais



More information about the Pyrex mailing list