[Numpy-discussion] Using arr.dtype.type to check byteorder-independed dtype fails for bool

Timothy Hochberg tim.hochberg@ieee....
Tue Nov 13 10:17:13 CST 2007


On Nov 13, 2007 6:57 AM, Sebastian Haase <haase@msg.ucsf.edu> wrote:

> On Nov 13, 2007 2:18 PM, Stefan van der Walt <stefan@sun.ac.za> wrote:
> > Hi Sebastian
> >
> > On Tue, Nov 13, 2007 at 01:11:33PM +0100, Sebastian Haase wrote:
> > > Hi,
> > > I need to check the array dtype in a way that it is ignoring
> > > differences coming only from big-endian vs. little-endian.
> >
> > Does
> >
> > N.issubdtype(first_dtype, second_dtype)
> >
> > work?
>
> Hi Stéfan !
> It appears to work :
>
> >>> N.empty(5, dtype=">f").dtype==N.float32
> False
> >>> N.empty(5, dtype="<f").dtype==N.float32
> True
> >>> a = N.empty(5, dtype=">f")
> >>> a.dtype
> >f4
> >>> a.dtype.type
> <type 'numpy.float32'>
> >>> N.issubdtype(a.dtype, N.float32)
> True
> >>> a = N.empty(5, dtype=">?")
> >>> a.dtype
> bool
> >>> a = N.empty(5, dtype="<?")
> >>> a.dtype
> bool
> >>> a = N.empty(5, dtype=">?")
> >>> N.issubdtype(a.dtype, N.bool)
> True
> >>> N.issubdtype(a.dtype, N.bool_)
> True
>
> Furthermore however,
> >>> N.empty(5, dtype=">?").dtype == N.empty(5, dtype="<?").dtype
> True
>
> So, for "symmetry reasons" with my existing non-bool code, I would
> likely use "arr.dtype.type == N.bool_".
> Still wondering what the "_" means here. (reading the book did not
> enlighten....)


Out of curiosity, does it work with arr.dtype.type == N.float? I would
expect not, and I imagine that is the same reason that it doesn't work for
N.bool. Which is that N.bool is __builtin__.bool or, in other words,
N.boolis just Python's boolean type.  I believe this is to protect
those foolish
enough to use "from x import *". Anyway, N.bool_ is the real, numpy boolean
dtype that is analogous to unit8 and friends.


>
>
> Thanks,
> Sebastian
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
.  __
.   |-\
.
.  tim.hochberg@ieee.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20071113/45bbd88f/attachment.html 


More information about the Numpy-discussion mailing list