numpy.isdtype#
- numpy.isdtype(dtype, kind)[source]#
Determine if a provided dtype is of a specified data type
kind.- Parameters:
- dtypedtype
The input dtype.
- kindDType class, str, or tuple of DType classes/strs.
The supported strings kinds are: *
'bool': boolean DType *'signed integer': signed integer data types *'unsigned integer': unsigned integer data types *'integral': integer data types *'real floating': real-valued floating-point data types *'complex floating': complex floating-point data types *'numeric': numeric data typesOtherwise should be a dtype class from the
numpy.dtypesnamespace. Concrete scalar types such asnp.float64are also acceptable.
- Returns:
- outbool
See also
Notes
After normalization of the input arguments, this function is equivalent to
isinstance(dtype, np.dtypes.<kind>).User defined dtypes pass these checks if their DType class inherits from the matching abstract DType in
numpy.dtypes. Additionally, a DType using theNPY_DT_NUMERICflag passes the"numeric"check.Examples
>>> import numpy as np >>> arr = np.array([1.0], dtype=np.float32) >>> np.isdtype(arr.dtype, np.float64) False >>> np.isdtype(arr.dtype, "real floating") True >>> np.isdtype(arr.dtype, ("real floating", "complex floating")) True >>> np.isdtype(np.dtype(">f8"), np.dtypes.Float64DType) True