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 types

Otherwise should be a dtype class from the numpy.dtypes namespace. Concrete scalar types such as np.float64 are also acceptable.

Returns:
outbool

See also

issubdtype

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 the NPY_DT_NUMERIC flag 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