If you are only comparing numpy types, you might be better off defining your comparison by the number that identifies each dtype, which is what C base code does. On my system, 12 is the number for np.float64 :
>>> np.dtype(np.float64).num 12 >>> np.float64(5.6).dtype.num 12 >>> np.array([5.6]).dtype.num 12
To use it also with values ββother than numpy, you can skip your way through it with something like:
def isdtype(a, dt=np.float64): try: return a.dtype.num == np.dtype(dt).num except AttributeError: return False
Jaime
source share