[Numpy-discussion] byteswap() not doing anything !?

Francesc Alted falted at openlc.org
Thu Feb 20 05:41:12 CST 2003

A Dimecres 19 Febrer 2003 21:42, Todd Miller va escriure:
> >   >>> print a
> >
> >   [1 2 3]
> >
> >   >>> a.byteswap()
> >   >>> print a
> >
> >   [16777216 33554432 50331648]
> This is a known bug/incompatability.  The behavior will be changed for
> the next release of numarray.  Right now,  _byteswap() does what you want.

This is already decided?. Because I like the present behaviour.

At first, I've found this behaviour a bit strange, but after get used to it,
I admit that it is elegant because you can always see a sane representation
of the data in array independently of which architecture you have written
the array.

If you byteswap() an array, the _byteorder property is also changed, so you
can check if your array is bytswapped or not just by writing:

if a._byteorder <> sys.byteorder:
    print "a is byteswapped"
    print "a is not byteswapped"

And, as you said before, you can always call _byteswap() if you *really*
want to *only* byteswap the array.

PyTables already makes use of byteswap() as it is now, and that's nice
because an array can be restored from disk safely by just looking at the
byte order on disk and then setting properly the ._byteorder attribute.
That's all! This allows also to work seamlessly with objects coming from a
mixture of big-endian and low-endian machines.

But, anyway, if you plan to do the change, may you please tell us what would
be the expected behaviour of the future .byteswap(), ._byteswap() and


Francesc Alted

More information about the Numpy-discussion mailing list