[Numpy-discussion] non-intuitive behaviour for isbyteswapped()?
jmiller at stsci.edu
Wed Jul 7 07:58:05 CDT 2004
On Tue, 2004-07-06 at 19:07, Philip Austin wrote:
> With numarray 1.0 and Mandrake 10 i686 I get the following:
> >>> y=N.array([1,1,2,1],type="Float64")
> >>> y
> array([ 1., 1., 2., 1.])
> >>> y.byteswap()
> >>> y
> array([ 3.03865194e-319, 3.03865194e-319, 3.16202013e-322,
> >>> y.isbyteswapped()
> Should this be 1?
The behavior of byteswap() has been controversial in the past, at one
time implementing exactly the behavior I think you expected.
Without giving any guarantee for the future, here's how things work
now: byteswap() just swaps the bytes. There's a related method,
togglebyteorder(), which inverts the sense of the byteorder:
The ability to munge bytes and change the sense of byteorder
independently is definitely needed... but you're certainly not the first
one to ask this question.
There is also (Numeric compatible) byteswapped(), which both swaps and
changes sense, but it creates a copy rather than operating in place:
>>> x = y.byteswapped()
>>> (x is not y) and (x._data is not y._data)
More information about the Numpy-discussion