[Numpy-discussion] Getting number of *characters* in dtype='U' array
Fri Sep 25 20:40:15 CDT 2009
On Fri, Sep 25, 2009 at 11:33:17AM -0400, Michael Droettboom wrote:
> Is there a way to get the number of characters in a fixed-size 'U'
> array? I can, of course, parse dtype.str, or divide dtype.itemsize by
> the size of a unicode character, but neither seems terribly elegant or
> future proof. Does numpy provide (to Python) a method for getting this
> that I'm just missing?
> In : x = np.array(u'1234')
> In : x.dtype
> Out: dtype('<U4')
> In : x.dtype.str
> Out: '<U4'
> In : x.dtype.itemsize
> Out: 16
I could be misleading you but I believe x.dtype.alignment is the divisor for itemsize that you're looking for?
It looks like it's 1 for string arrays and 4 for Unicode arrays, which would make sense...
More information about the NumPy-Discussion