[Numpy-discussion] trivial question: how to compare dtype - but ignoring byteorder ?

Sebastian Haase haase at msg.ucsf.edu
Mon Jul 24 19:31:53 CDT 2006


On Monday 24 July 2006 16:42, Bill Baxter wrote:
> > > And I think byteorder matters when comparing dtypes:
> > > >>> numpy.dtype('>f4') == numpy.dtype('<f4')
> > >
> > > False
>
> Ohhhhh -- that '<' part is indicating *byte order* ?!
> I thought it was odd that numpy could only tell me the type was "less
> than f4", which I assumed must be shorthand for "less than or equal to
> f4".  Makes much more sense now!
>
> --bb
Which is why I was trying to change the str() representation of a type to 
something more intuitive. 
If nothing else one could even leave 
repr(a.dtype)  --> '<i4'
but 
str(a.dtype)    --> 'int32 (little endian)'

I do now understand that (as opposed to numarray and numeric) the byteorder is 
now part of the data-type  - but I would really encourage keeping the string 
for such an important (and often used !) thing more readable than
"<i4".   
Most people will thankfully never have to think about byteorder - it should be 
like an implementation detail that numpy can transparently handle ! 

What what it's worth ,
Sebastian Haase





More information about the Numpy-discussion mailing list