On May 30, 4:53 pm, sturlamolden <[EMAIL PROTECTED]> wrote:

> import numpy
>
> byte = numpy.uint8
> desc = numpy.dtype({'names':['r','g','b'],'formats':[byte,byte,byte]})
> mm = numpy.memmap('myfile.dat', dtype=desc, offset=4096,
> shape=(480,640), order='C')
> red = mm['r']
> green = mm['g']
> blue = mm['b']

An other thing you may commonly want to do is coverting between numpy
uint8 arrays and raw strings. This is done using the methods
numpy.fromstring and numpy.tostring.

# reading from file to raw string
rstr = mm.tostring()

# writing raw string to file
mm[:] = numpy.fromstring(rstr, dtype=numpy.uint8)
mm.sync()










-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to