When using numpy array the type of the array is given by the "dtype"
variable of the array. So if your array is int then array.dtype will
be 'int32'. Numpy uses more complex data types then just int and
floats so you might want to check all the available data types.
Ex:
In [168]: a = array([1,2,3])
In [169]: a.dtype
Out[169]: dtype('int32')
OR (Array)
In [170]: b = array([1.,2.,3.])
In [171]: b.dtype
Out[171]: dtype('float64')
OR (Strings)
In [172]: c = array(['sdf', 'fff', 'tye'])
In [173]: c.dtype
Out[173]: dtype('|S3') # This could also be 'Sxxx' where xxx is the
length of the largest string in the array
Alternatively, as a hackjob type check you could also do an
"isinstance" check on the first element of the array since, unlike
lists, arrays have uniform elements all the way through.
Hope that helps,
- Simon Berube
P.S.: Someone please correct me if there's a better way.
On Apr 29, 6:51 am, dmitrey <[EMAIL PROTECTED]> wrote:
> 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]) .
> Thx, D.
>
> _______________________________________________
> Numpy-discussion mailing list
> [EMAIL PROTECTED]://projects.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion