numpy.asarray: how to check up that its result dtype is numeric?

You could check if the dtype of the array is a sub-dtype of np.number. For example:

>>> np.issubdtype(np.complex128, np.number)
True
>>> np.issubdtype(np.int32, np.number)
True
>>> np.issubdtype(np.str_, np.number)
False
>>> np.issubdtype('O', np.number) # 'O' is object
False

Essentially, this just checks whether the dtype is below ‘number’ in the NumPy dtype hierarchy:

enter image description here

Leave a Comment

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