Is a number float64?
Use isinstance:
>>> f = numpy.float64(1.4)
>>> isinstance(f, numpy.float64)
True
>>> isinstance(f, float)
True
numpy.float64 is inherited from python native float type. That because it is both float and float64 (@Bakuriu thx for pointing out). But if you will check python float instance variable for float64 type you will get False
in result:
>>> f = 1.4
>>> isinstance(f, numpy.float64)
False
>>> isinstance(f, float)
True
I find this is the most readable method for checking Numpy number types
import numpy as np
npNum = np.array([2.0])
if npNum.dtype == np.float64:
print('This array is a Float64')
# or if checking for multiple number types:
if npNum.dtype in [
np.float32, np.float64,
np.int8, np.uint8,
np.int16, np.uint16,
np.int32, np.uint32,
np.int64, np.uint64
]:
print('This array is either a float64, float32 or an integer')