[SciPy-User] Integer dtype comparisons

Paul Barrett pebarrett at gmail.com
Sat Sep 25 19:53:05 EDT 2010


Have you tried issubdtype ?

>>> numpy.issubdtype(numpy.int32, numpy.int)
True

On Wed, Sep 22, 2010 at 8:04 AM, Michael Pimmer <michael at pimmer.info> wrote:
> Hello,
>
> is there a nice way to check whether an object is an Integer? Including
> all python and numpy Integers?
>
> I tried out subclass, but uint is not a subclass of Int:
>
>  >>> a = numpy.zeros(1,numpy.uint32)
>  >>> aType = type(a[0])
>  >>> issubclass(aType,types.IntType)
> False
>
>
> I tried out enumerating, but numpy seems to slightly change datatypes
> during some calculations, which complicates comparisons:
>
>  >>> a = numpy.zeros(1,numpy.uint8)
>  >>> aValue = a[0]
>  >>> b = numpy.zeros(1,numpy.int32)
>  >>> bValue = b[0]
>  >>> result = aValue + bValue
>  >>> type(result)
> <type 'numpy.int32'>
>  >>> numpy.int32
> <type 'numpy.int32'>
>  >>> type(result) == numpy.int32
> False
>
>
> thanks,
> Michael
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list