[Numpy-discussion] numpy uint16 array to unicode string

Robert Kern robert.kern@gmail....
Sat Feb 25 13:56:38 CST 2012


On Sat, Feb 25, 2012 at 19:50, Janwillem <jwevandijk@xs4all.nl> wrote:
> I have a buffer as a numpy array of uint16. Chunks of this buffer are
> unicode characters. How do I get these chunks, say data[start:end], in a
> string?

data[sart:end].tostring().decode('UTF-16LE')

or 'UTF-16BE' if they are big-endian.

> Other chunks are 32bit integers how do I get these chunks into a numpy
> array of int32?

data[start:end].view(np.int32)

-- 
Robert Kern


More information about the NumPy-Discussion mailing list