How to check if a number is a np.float64 or np.float32 or np.float16?

You can use np.floating:

In [11]: isinstance(np.float16(1), np.floating)
Out[11]: True

In [12]: isinstance(np.float32(1), np.floating)
Out[12]: True

In [13]: isinstance(np.float64(1), np.floating)
Out[13]: True

Note: non-numpy types return False:

In [14]: isinstance(1, np.floating)
Out[14]: False

In [15]: isinstance(1.0, np.floating)
Out[15]: False

to include more types, e.g. python floats, you can use a tuple in isinstance:

In [16]: isinstance(1.0, (np.floating, float))
Out[16]: True

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)