On Fri, Jun 3, 2011 at 1:46 PM, Neal Becker <[email protected]> wrote:

> Can I arrange to reinterpret an array of complex of length N as an array of
> float of length 2N, and vice-versa?  If so, how?
>


You can use the view() method (if the data is contiguous):

In [14]: z = array([1.0+1j, 2.0+3j, 4, 9j])

In [15]: x = z.view(float64)

In [16]: x
Out[16]: array([ 1.,  1.,  2.,  3.,  4.,  0.,  0.,  9.])


But this won't work if the data in the array is not contiguous:

In [17]: z2 = z[::2]

In [18]: z2
Out[18]: array([ 1.+1.j,  4.+0.j])

In [19]: z2.view(float64)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

/Users/warren/<ipython console> in <module>()

ValueError: new type not compatible with array.


(I'm using ipython with the -pylab option; 'array' and 'float64' are from
numpy.)


Warren



>
> _______________________________________________
> NumPy-Discussion mailing list
> [email protected]
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to