NumPy provides base classes that you can/should use for subtype-checking, rather than the Python types.
Use np.integer
to check for any instance of either signed or unsigned integers.
Use np.signedinteger
and np.unsignedinteger
to check for signed types or unsigned types.
>>> np.issubdtype(np.uint32, np.integer)
True
>>> np.issubdtype(np.uint32, np.signedinteger)
False
>>> np.issubdtype(int, np.integer)
True
All floating or complex number types will return False
when tested.
np.issubdtype(np.uint*, int)
will always be False
because the Python int
is a signed type.
A useful reference showing the relationship between all of these base classes is found in the documentation here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…