[Pyrex] Numeric and Pyrex
len-l at telus.net
len-l at telus.net
Tue Sep 20 06:06:38 CEST 2005
On 19 Sep 2005 at 15:45, Nitin Madnani wrote:
> 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 !
The Numeric.Float is a C double, like the Python float.
>>> import Numeric
>>> Numeric.Float
'd'
Lenard Lindstrom
<len-l at telus.net>
More information about the Pyrex
mailing list