[Numpy-discussion] Reading from binary file with memmap, with offset
lists at hilboll.de
Thu Oct 10 09:17:26 EDT 2013
On 10.10.2013 15:07, Joe Kington wrote:
> You just need to supply the "offset" kwarg to "memmap".
> for example:
> with open(localfile, "r") as fd:
> # read offset from first line of file
> offset = int(next(fd).split()[-2])
> np.memmap(fd, dtype="float32", mode="r", offset=offset)
> Also, there's no need to do things like "offset =
> Just do "offset = int(next(fd).split()[-2])" instead. Readlines reads
> the entire file into memory. You only want the first line.
Thanks, Joe, I actually didn't know `next` yet ...
More information about the NumPy-Discussion