[Numpy-discussion] reading big-endian uint16 into array on little-endian machine

Robert Kern robert.kern@gmail....
Fri Jun 18 09:45:20 CDT 2010

On Fri, Jun 18, 2010 at 09:39, Benjamin Root <ben.v.root@gmail.com> wrote:

> Just for my own knowledge, would Robert's suggestion of using '>i2' as the
> dtype be considered the "best" solution, mostly because of its simplicity,
> but also because it does not assume the endian-ness of the host computer?

It does come with the tradeoff that math will be a little bit slower
on it. A quick .astype(np.uint16) will fix that. That said, the cost
of creating the memory for the new native array will probably wipe
away those gains unless if the data is reused a number of times for

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco

More information about the NumPy-Discussion mailing list