[SciPy-user] accessing contents of complex numpy array from pyrex

Lev Givon lev@columbia....
Mon Jan 7 14:36:06 CST 2008


Received from Robert Kern on Mon, Jan 07, 2008 at 01:41:00PM EST:
> Lev Givon wrote:
> > Does anyone know how to access the elements of a 1-D numpy array
> > containing complex values from within a function written in pyrex?
> > Since pyrex currently doesn't provide a straightforward interface to
> > complex data types, I was wondering whether there is some way to
> > access the real and imaginary portions of each element in the data
> > block of the array directly.
> 
> One way would be to define a my_complex struct in a .h file, expose
> it in Pyrex, and cast the data pointer to <my_complex*>:
> 
> (snip)

Thanks; this did work. Being that I also needed to perform various
operations on the array elements, I found it preferable to wrap the C
complex type provided by complex.h with a struct and then define C
macros for the various arithemtic/transcendental operations I needed.

       	       	       				 L.G.



More information about the SciPy-user mailing list