Wed, 29 Jul 2009 10:20:19 -0400, Neal Becker kirjoitti:
[clip]
> Can 'view' switch byteorder?  Doesn't seem to work:
[clip]

I think not: view only alters the dtype, ie., the interpretation of the 
block of memory. It does not physically reorder the data in memory, which 
is necessary for unpacking to a different byte order.

The reliable way to unpack seems to be

        np.asarray(a, dtype='<u4').view('u1')

which avoids copies when possible. Of course, you could do

        if a.dtype.newbyteorder('<') != a.dtype:
            a.byteswap(True)
        b = a.view('u1')

to byte-swap in-place to little-endian order.

-- 
Pauli Virtanen

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

Reply via email to