[Numpy-discussion] byteswap() leaves dtype unchanged

Matthew Brett matthew.brett at gmail.com
Wed May 30 09:57:19 EDT 2007


Hi,

> > 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.
>
> By "numbers have still changed" I mean the underlying byte order is
> still different, but you can now use the object for mathematical
> operations.  My point is that the metadata for the object should be
> correct after using it's built-in methods.

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.

Best,

Matthew



More information about the NumPy-Discussion mailing list