numpy.issubdtype#
- numpy.issubdtype(arg1, arg2)[source]#
Returns True if first argument is a typecode lower/equal in type hierarchy.
Note
This function relies on the scalar type hierarchy. That works in practice for NumPy dtypes and some user defined ones, but does not generalize.
isdtypehas slightly clearer semantics, although NumPy 2.6 or later is required for it to work with user defined dtypes in general.- Parameters:
- arg1, arg2dtype_like
dtypeor object coercible to one
- Returns:
- outbool
See also
Examples
issubdtypecan be used to check the type of arrays:>>> ints = np.array([1, 2, 3], dtype=np.int32) >>> np.issubdtype(ints.dtype, np.integer) True >>> np.issubdtype(ints.dtype, np.floating) False
>>> floats = np.array([1, 2, 3], dtype=np.float32) >>> np.issubdtype(floats.dtype, np.integer) False >>> np.issubdtype(floats.dtype, np.floating) True
Similar types of different sizes are not subdtypes of each other:
>>> np.issubdtype(np.float64, np.float32) False >>> np.issubdtype(np.float32, np.float64) False
but both are subtypes of
floating:>>> np.issubdtype(np.float64, np.floating) True >>> np.issubdtype(np.float32, np.floating) True
For convenience, dtype-like objects are allowed too:
>>> np.issubdtype('S1', np.bytes_) True >>> np.issubdtype('i4', np.signedinteger) True