How can I check that a numpy array if of float or complex dtype? For simple examples the following checks all work fine.
# these are True
a = np.zeros(10)
a.dtype == float
a.dtype == np.float
a.dtype == np.float64
b = np.zeros(10,dtype=complex)
b.dtype == complex
b.dtype == np.complex
b.dtype == np.complex128
However, I have an array of dtype dtype('>f8'). None of the previous comparisons identifies it as a float array. As far as I can see the endianness (> vs. <) is the issue there. Is there any general function to check whether the array is float or complex with all variations?
np.iscomplexobjtests thetypeof thedtype:issubclass(arr.dtype.type, np.complexfloating). The base dtypes have several levels of subclassing, so simple '==' tests don't always work.