How do I find out if a numpy array contains integers?

后端 未结 5 1133
一个人的身影
一个人的身影 2021-02-03 18:46

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

5条回答
  •  孤独总比滥情好
    2021-02-03 19:23

    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
    

提交回复
热议问题