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
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
Also b = a[0::2] + a[1::2]*1.0j -----Original Message----- From: numpy-discussion-admin@lists.sourceforge.net [mailto:numpy-discussion-admin@lists.sourceforge.net]On Behalf Of Warren Focke Sent: Tuesday, March 13, 2001 6:00 PM To: Eric Hagemann Cc: Numpy-discussion@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@lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/numpy-discussion
participants (3)
-
Eric Hagemann
-
Paul F. Dubois
-
Warren Focke