[Numpy-discussion] getting data pointer to numpy object in Pyrex
Brian Blais
bblais at bryant.edu
Tue Mar 28 14:34:02 CST 2006
Hello,
I posted this on the Pyrex list, but I figured someone here may be able to answer it too.
Is here an easy way, in Pyrex, 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 Numpy-discussion
mailing list