[Numpy-discussion] Type checking of arrays containing strings

Stéfan van der Walt stefan at sun.ac.za
Fri Jul 18 05:40:54 EDT 2008


2008/7/18 Arnar Flatberg <arnar.flatberg at gmail.com>:
> I need to check if my array (a) is of type `string`. That is, I dont know
> the number of characters beforehand, so I cant do a.dtype == '|S*' (* =
> (max) number of characters)
> Looking at my options,  I see either a.dtype.kind == 'S' or a.dtype.type ==
> np.string_, might be ok. Are these any of the preffered ways, or is there
> some other way?

Maybe

np.issubdtype(x.dtype, str)

Stéfan



More information about the NumPy-Discussion mailing list