On 5/30/07, Francesc Altet <[EMAIL PROTECTED]> wrote:
> El dt 29 de 05 del 2007 a les 14:17 -0400, en/na Erin Sheldon va
> escriure:
> > Hi all -
> >
> > I have read some big-endian data and I want to byte swap it to little
> > endian.  If I use
> >   a.byteswap(True)
> > the bytes clearly get swapped, but the dtype is not updated to reflect
> > the new data type.  e.g
> >
> > [~]|1> a=N.array([2.5, 3.2])
> > [~]|2> a.dtype.descr
> >    <2> [('', '<f8')]
> > [~]|3> a.byteswap(True)
> >    <3> array([  5.37543423e-321,  -1.54234871e-180])
> > [~]|4> a.dtype.descr
> >    <4> [('', '<f8')]
> >
> > I expected the dtype to be changed so that the print of the array
> > would look the same as before, and mathematical operations would work
> > properly. This can be done with:
> >   a.dtype = a.dtype.newbyteorder()
>
> Yes. That's the canonical way to do what you want.
>
> > Should this not be performed by byteswap()?
>
> No. From the Travis' "Guide to NumPy":
>
> """
> byteswap ({False})
>
> Byteswap the elements of the array and return the byteswapped array. If
> the argument is True, then byteswap in-place and return a reference to
> self. Otherwise, return a copy of the array with the elements
> byteswapped. The data-type descriptor is not changed so the array will
> have changed numbers.
> """

This doesn't make any sense.  The numbers have changed but the dtype
is now incorrect.  If you byteswap and correct the dtype the numbers
have still changed, but you now can actually use the object.



>
> Cheers,
>
> --
> Francesc Altet    |  Be careful about using the following code --
> Carabos Coop. V.  |  I've only proven that it works,
> www.carabos.com   |  I haven't tested it. -- Donald Knuth
>
> _______________________________________________
> Numpy-discussion mailing list
> [email protected]
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to