[Numpy-discussion] problem reading binary data from file

Christopher Barker Chris.Barker at noaa.gov
Fri Apr 6 12:54:09 EDT 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.

-Chris





-- 
Christopher Barker, Ph.D.
Oceanographer

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

Chris.Barker at noaa.gov



More information about the NumPy-Discussion mailing list