[Numpy-discussion] Native byteorder representation

Francesc Altet faltet at carabos.com
Fri Feb 2 13:11:11 EST 2007


El dv 02 de 02 del 2007 a les 10:22 -0700, en/na Travis Oliphant va
escriure:
> Francesc Altet wrote:
> 
> >Hi,
> >
> >We have been bitten by a small glitch related with the representation of 
> >native byteorders. Here is an example exposing the problem:
> >
> >  
> >
> >>>>numpy.dtype('<i4').byteorder
> >>>>        
> >>>>
> >'='
> >  
> >
> >>>>numpy.dtype('>i4').newbyteorder('little').byteorder
> >>>>        
> >>>>
> >'<'
> >
> >  
> >
> This is somewhat inconsistent.  But, I'm not sure it's worth changing.  
> 
> In the second case, you request a "little" byteorder data-type.  Keeping 
> this as '<' seems O.K.
> 
> One could instead ask why the first example did not report a byte-order 
> of "<" when that's what was explicitly asked for.

Well, just because of the same reason that

numpy.dtype('<i4').byteorder

returns a '=' instead of a '<' (the latter being explicitely set in the
constructor).

I think that returning a '=' whenever the byteorder is the same than the
underlying machine is desirable because the user can quickly see whether
her data is in native order or not.

Cheers,

-- 
Francesc Altet    |  Be careful about using the following code --
Carabos Coop. V.  |  I've only proven that it works, 
www.carabos.com   |  I haven't tested it. -- Donald Knuth




More information about the NumPy-Discussion mailing list