[Numpy-discussion] reading gzip compressed files using numpy.fromfile

Christopher Barker Chris.Barker@noaa....
Wed Oct 28 15:26:41 CDT 2009


Robert Kern wrote:
>>        f=gzip.open( "myfile.gz", "r" )
>> xyz=npy.fromfile(f,dtype="float32",count=400)

> Read in reasonably-sized chunks of bytes at a time, and use
> np.fromstring() to create arrays from them.

Something like:

count = 400
xyz = np.fromstring(f.read(count*4), dtype=np.float32)

should work (untested...)

-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@noaa.gov


More information about the NumPy-Discussion mailing list