tags:

views:

274

answers:

2

I know there is a simple solution to this but can't seem to find it at the moment.

Given a numpy array, I need to know if the array contains integers.

Checking the dtype per-se is not enough, as there are multiple int dtypes (int8, int16, int32, int64 ...).

+4  A: 

Found it in the numpy book! Page 23

The other types in the hierarchy define particular categories of types. 
These categories can be useful for testing whether or not the object 
returned by self.dtype.type is of a particular class (using issubclass).
issubclass(n.dtype('int8').type, n.integer)
>>> True
issubclass(n.dtype('int16').type, n.integer)
>>> True
saffsd
+1  A: 

This also works:

  n.dtype('int8').kind == 'i'