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

Sebastian Haase haase at msg.ucsf.edu
Mon Jul 24 14:10:07 EDT 2006


On Monday 24 July 2006 03:18, Karol Langner wrote:
> On Monday 24 July 2006 06:47, Sebastian Haase wrote:
> > Hi,
> > if I have a numpy array 'a'
> > and say:
> > a.dtype == numpy.float32
> >
> > Is the result independent of a's byteorder ?
> > (That's what I would expect ! Just checking !)
> >
> > Thanks,
> > Sebastian Haase
>
> The condition will always be False, because you're comparing wrong things
> here, numpy.float32 is a scalar type, not a dtype.

Hi !
 Thanks for the reply.
Did you actually run this ? I get:
#>>> a=N.arange(10, dtype=N.float32)
#>>> a.dtype == N.float32
#True
#>>> N.__version__
#'0.9.9.2823'


>
> >>> numpy.float32
>
> <type 'float32scalar'>
>
> >>> type(numpy.dtype('>f4'))
>
> <type 'numpy.dtype'>
>
> And I think byteorder matters when comparing dtypes:
> >>> numpy.dtype('>f4') == numpy.dtype('<f4')
> False

OK - I did a test now:
#>>> b= a.copy()
#>>> b=b.newbyteorder('big')
#>>> a.dtype == b.dtype
#False
#>>> a.dtype
#'<f4'
#>>> b.dtype
#'>f4'

How can I do a comparison showing that both a and b are float32 ??

Thanks,
Sebastian Haase





More information about the NumPy-Discussion mailing list