[Numpy-discussion] simpliest way to check: array x is float, not integer
Mon Apr 30 11:31:13 CDT 2007
> hi all,
> please inform me what is the simplest way to check, does the vector x
> that came to my func is float or integer. I.e. someone can pass to my
> func for example x0 = numpy.array([1, 0, 0]) and it can yield wrong
> unexpected results vs numpy.array([1.0, 0, 0]) .
Usually, it's not so much that you need to know whether a parameter is a
float or an integer, but rather that your function is designed to work
with one or the other. In that case, you can force it with as array:
InputArray = numpy.asarray(InputArray, numpy.float)
asarray is a no-op if the input is already of the type you've specified
It's handy, as it will take *anything* that can be turned into an array
of the specified type.
This won't work the function needs to change the input in place, however.
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
More information about the Numpy-discussion