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

Sebastian Haase haase@msg.ucsf....
Tue Jul 3 03:34:33 CDT 2007


Thanks for the reply.
Rethinking the question ... wasn't there an attribute named something like:
is_native()
??

The a.dtype.str[0]  is certainly better than nothing ... just doesn't
look very good ;-)

-Sebastian




On 7/3/07, Francesc Altet <faltet@carabos.com> wrote:
> 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@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'>


More information about the Numpy-discussion mailing list