python - How to check if all elements of a numpy.array are of the same data type? -


i have few numpy arrays, can formatted as

[1.525, 2.565, 6.367, ...]  # elements float numbers 

or

['', '', '', ...]  # elements empty strings 

i'd find out if elements in array of same data type.

for now, using:

if isinstance(np.any(time_serie),float):     return sum(time_serie) 

but 1 doesn't work. got following error:

typeerror: cannot perform reduce flexible type 

so, may know how work around this? thanks.

if you're looking particular data-type provided in example, e.g. items floats, map , reduce trick:

>>> x = [1.525, 2.565, 6.367]  >>> all(map(lambda i: isinstance(i, float), x))     true  >>> x = [1.525, 2.565, '6.367']  >>> all(map(lambda i: isinstance(i, float), x))     false 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -