[Numpy-discussion] Getting number of *characters* in dtype='U' array
Fri Sep 25 10:52:14 CDT 2009
Ah, I missed the fact that Numpy unicode characters are always 4-bytes,
unlike Python unicode objects. Divide by 4 is easy enough. Sorry for
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
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA
More information about the NumPy-Discussion