[Numpy-discussion] conversion to complex

Paul F. Dubois paul at pfdubois.com
Wed Mar 14 00:32:42 CST 2001


Also b = a[0::2] + a[1::2]*1.0j

-----Original Message-----
From: numpy-discussion-admin at lists.sourceforge.net
[mailto:numpy-discussion-admin at lists.sourceforge.net]On Behalf Of Warren
Focke
Sent: Tuesday, March 13, 2001 6:00 PM
To: Eric Hagemann
Cc: Numpy-discussion at lists.sourceforge.net
Subject: Re: [Numpy-discussion] conversion to complex



> >>> a=array([1,2,3,4], 'f')
> >>> b=zeros(len(a)/2, 'F')
> >>> b.real=a[0:4:2]
> >>> b.imag=a[1:4:2]
> >>> b
> array([ 1.+2.j,  3.+4.j],'F')

or, if you feel brave

> >>> c=fromstring(a.tostring(), 'F')
> >>> c
> array([ 1.+2.j,  3.+4.j],'F')

wbf

On Tue, 13 Mar 2001, Eric Hagemann wrote:

> I have an array of floats that is an interleaved stream of complex
(real/imag) values that I want to promote to complex.  My current method
uses the following
>
> a=array([1,2,3,4])
>
> b = a[0:4:2] + cmath.sqrt(-1)*a[1:4:2]
>
> Is there a more elegant way ?  I am hoping to avoid explicit for loops etc
>


_______________________________________________
Numpy-discussion mailing list
Numpy-discussion at lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/numpy-discussion





More information about the Numpy-discussion mailing list