[Numpy-discussion] arr.dtype.byteorder == '=' --- is this "good code"

Francesc Altet faltet at carabos.com
Tue Jul 3 03:46:18 EDT 2007


El dt 03 de 07 del 2007 a les 08:35 +0200, en/na Sebastian Haase va
escriure:
> any comments !?
> 
> On 6/25/07, Sebastian Haase <haase at msg.ucsf.edu> wrote:
> > Hi,
> > Suppose I'm on a little-edian system.
> > Could I have a little-endian numpy array arr, where
> > arr.dtype.byteorder
> > would actually be "<"
> > instead of  "=" !?

You can always use arr.dtype.str[0], which I think it always returns a
'<', '>' or '|':

In [2]:a=numpy.array([1])
In [3]:a.dtype.byteorder
Out[3]:'='
In [4]:a.dtype.str
Out[4]:'<i4'
In [5]:a.dtype.str[0]
Out[5]:'<'

> > There are two kinds of systems: little edian and big endian.
> > But there are three possible byteorder values: "<", ">" and "="
> >
> > I assume that if arr.dtype.byteorder is "="
> > then, even on a little endian system
> > the comparison arr.dtype.byteorder == "<"  still fails !?
> > Or are the == and != operators overloaded !?

No, this will fail.  The == and != are not overloaded because
dtype.byteorder is a pure python string:

In [11]:type(a.dtype.byteorder)
Out[11]:<type 'str'>

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