This seems like it should be super simple, but the answer is eluding me. I Have done a bunch of google-searches for the answer but don't feel like any of the results really answered my question, perhaps I'm just searching for the wrong thing? please help:
I am writing a function:
def cheese(array_like, *args, **kwargs):
if dtype_of_(array_like) is float:
return "macaroni"
The part dtype_of_(array_like) is float
is obviously not functioning code, just something I wrote to give you an idea of what I am trying to accomplish.
What I need is to check whether the input is an iterable of floats (any type of float) or a float. Ie. the input "array_like" can be any iterable which can be converted to a numpy array or can even be a 0-dimensional array or a scalar.
I found this seemingly very similar question here, but I don't feel that it answered my question.
I also found this other similar question here, but this just concerns scalars, not arrays..
What I have done so far is to do:
def cheese(array_like, *args, **kwargs):
np.array(array_like, copy=False).dtype == np.floating:
return "macaroni"
But although this works it also gives me a deprecation warning:
DeprecationWarning: Converting
np.inexact
ornp.floating
to a dtype is deprecated. The current result isfloat64
which is not strictly correct. if np.array(array_like, copy=False).dtype == np.floating: