[Numpy-discussion] problem reading binary data from file

Christopher Barker Chris.Barker@noaa....
Fri Apr 6 11:54:09 CDT 2007

Pierre GM wrote:
> With numpy.core.records, you create a record array. Just get the field ('f0' 
> by default) to get a ndarray.

there is. Don't use numpy.core.records. Use numpy.fromfile:

import numpy

a = numpy.fromfile(filename, dtype=numpy.int16)

(filename can be a filename, or an open file object)

You may want to get fancier with the dtype to force the correct byte order.


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception


More information about the Numpy-discussion mailing list