[Numpy-discussion] Getting number of *characters* in dtype='U' array

David Warde-Farley dwf@cs.toronto....
Fri Sep 25 20:57:27 CDT 2009


On Fri, Sep 25, 2009 at 09:15:49PM -0500, Robert Kern wrote:

> > I could be misleading you but I believe x.dtype.alignment is the divisor for itemsize that you're looking for?
> 
> Only by happenstance. It is not really related.

Yikes, my guess was quite wrong indeed.

http://docs.scipy.org/doc/numpy/reference/c-api.types-and-structures.html#alignment

I'd say go with int(dt.str.split(dt.char)[-1]). That's not _that_ brittle, I guess. I was just looking at the C code 
for this the other day, and the way it's implemented is that if you've specified unicode the elsize is left-shifted 
by 2. I don't think the 'atom size' is stored anywhere in the process.

David


More information about the NumPy-Discussion mailing list