[SciPy-User] Integer dtype comparisons

Michael Pimmer michael@pimmer.i...
Wed Sep 22 07:04:09 CDT 2010


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


More information about the SciPy-User mailing list