[Pyrex] Numeric and Pyrex
Nitin Madnani
nmadnani at wam.umd.edu
Mon Sep 19 21:45:36 CEST 2005
Thanks so much Lenard !! That was dumb of me.
However, I still can't figure out how to do the actual-fill in of the
Numeric array. The example included with Pyrex shows how to read from
a given array and now how to fill in one. I just figured that it's
probably done in a similar way but it doesn't seem to be working.
Probably another dumb error:
import Numeric
cdef extern from "/nfshomes/nmadnani/local/include/python2.4/Numeric/
arrayobject.h":
struct PyArray_Descr:
int type_num, elsize
char type
ctypedef class Numeric.ArrayType [object PyArrayObject]:
cdef char *data
cdef int nd
cdef int *dimensions, *strides
cdef object base
cdef PyArray_Descr *descr
cdef int flags
def test():
cdef int i,j, index
cdef float *elems
cdef ArrayType m
m = Numeric.ones((3, 3), Numeric.Float)
elems = <float *>m.data
elems[1] = 3.0
return m
After compilation and usage in a test python file, this returns the
following array:
[[ 32. 1. 1.]
[ 1. 1. 1.]
[ 1. 1. 1.]]
Therefore, I guess this is not the way to fill in the array.
Thanks in advance !
Nitin
More information about the Pyrex
mailing list