1 May 14:05
Re: simpliest way to check: array x is float, not integer
Simon Berube <sberub <at> gmail.com>
2007-05-01 12:05:20 GMT
2007-05-01 12:05:20 GMT
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
(Continue reading)
RSS Feed