On Thu, May 27, 2010 at 6:02 AM, Vincent Davis <vinc...@vincentdavis.net> wrote: > > On Thu, May 27, 2010 at 1:27 AM, Francesc Alted <fal...@pytables.org> wrote: >> >> A Thursday 27 May 2010 05:52:22 Vincent Davis escrigué: >> > How do I determine if an array's (or column in a structured array) dtype is >> > a number or a string. I see how to determine the actual dtype but all I >> > want to know is if it is a string or a number. >> >> I suppose that the `.kind` attribute of dtype would help you: >> >> In [2]: s = np.dtype("S3") >> >> In [4]: s.kind >> Out[4]: 'S' >> >> In [5]: i = np.dtype("i4") >> >> In [6]: i.kind >> Out[6]: 'i' >> >> In [7]: f = np.dtype("f8") >> >> In [8]: f.kind >> Out[8]: 'f' > > I know about this but the problem is that while the fist example is usable, > the others are not great because to know that it is a number I would need to > do something like(see below) but I might miss a number dtype, > def is_number(obj): > if obj.dtype.kind in ('i', 'f',..): > return True >> >> Pierre GM "Check `numpy.lib._iotools._is_string_like`" > > This is ok, but I am having problem making it work, I keep getting an error > that I am giving it 2 items and it only takes 1. Obviously I think I am > giving it 1. This of course tells me if it is string like but not that "is" a > number. > Thanks > Vincent
To see if it is a number could you use something like: np.issubdtype(a.dtype, float) or np.issubdtype(a.dtype, int) or np.issubdtype(a.dtype, complex) And for string: np.issubdtype(a.dtype, str) _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion