I was looking for a way to convert a complex array to a 2D float array in place and found this:
> print np.empty(10, dtype='complex128').reshape(-1,1).view(dtype='float64').shape
> (10,2)
Interestingly, using [:,newaxis] to add the extra dimension fails:
> print np.empty(10, dtype='complex128')[:,np.newaxis].view(dtype='float64').shape
> ValueError: new type not compatible with array.
This related thread discusses that both reshape
and newaxis
create a view but there are differences in how the strides are set:
Numpy: use reshape or newaxis to add dimensions
How does this creating a float view on a complex array?