[Numpy-discussion] Float view of complex array
Sebastian Berg
sebastian at sipsolutions.net
Mon Jan 26 04:41:35 EST 2015
On Mo, 2015-01-26 at 09:24 +0100, Jens Jørgen Mortensen wrote:
> Hi!
>
> I have a view of a 2-d complex array that I would like to view as a 2-d
> float array. This works OK:
>
> >>> np.ones((2, 4), complex).view(float)
> array([[ 1., 0., 1., 0., 1., 0., 1., 0.],
> [ 1., 0., 1., 0., 1., 0., 1., 0.]])
>
> but this doesn't:
>
> >>> np.ones((2, 4), complex)[:, :2].view(float)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: new type not compatible with array.
> >>> np.__version__
> '1.9.0'
>
> and I don't understand why. When looking at the memory layout, I think
> it should be possible.
>
Yes, it should be possible, but it is not :). You could hack it by using
`np.ndarray` (or stride tricks). Or maybe you are interested making the
checks whether it makes sense or not less strict.
- Sebastian
> Jens Jørgen
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150126/e0024471/attachment.sig>
More information about the NumPy-Discussion
mailing list