On 30/05/07, Matthew Brett <[EMAIL PROTECTED]> wrote:

> I think the point is that you can have several different situations
> with byte ordering:
>
> 1) Your data and dtype endianess match, but you want the data swapped
> and the dtype to reflect this
>
> 2) Your data and dtype endianess don't match, and you want to swap the
> data so that they match the dtype
>
> 3) Your data and dtype endianess don't match, and you want to change
> the dtype so that it matches the data.
>
> I guess situation 1 is the one you have, and the way to deal with this
> is, as you say:
>
> other_order_arr = one_order_arr.byteswap()
> other_order_arr.dtype.newbyteorder()
>
> The byteswap method is obviously aimed at situation 2 (the data and
> dtype don't match in endianness, and you want to swap the data).
>
> I can see your point I think, that situation 1 seems to be the more
> common and obvious, and coming at it from outside, you would have
> thought that a.byteswap would change both.

I think the reason that byteswap behaves the way it does is that for
situation 1 you often don't actually need to do anything. Just
calculate with the things (it'll be a bit slow); as soon as the first
copy gets made you're back to native byte order. So for those times
you need to do it in place it's not too much trouble to byteswap and
adjust the byte order in the dtype (you'd need to inspect the byte
order in the first place to know it was byteswapped...)

Anne
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to