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
While the accepted answer from 2009 is still valid, there is a new and enhanced solution as of Numpy v0.19, released in September 2014:
All numerical numpy types are now registered with the type hierarchy in the python numbers module.
This allows for checking the dtype
against Python's Numeric abstract base classes.
isinstance(np.dtype('int8'), numbers.Integral)
issubclass(np.dtype('int32').type, numbers.Integral)
You can test against numbers.Complex
, numbers.Real
and numbers.Integral
.
P.S. As you don't need to access .type
anymore you can shorten your line by a few characters now. ;)