[Numpy-discussion] R: R: R: fast numpy.fromfile skipping data chunks

Nathaniel Smith njs at pobox.com
Wed Mar 13 10:53:25 EDT 2013

On Wed, Mar 13, 2013 at 2:46 PM, Andrea Cimatoribus
<Andrea.Cimatoribus at nioz.nl> wrote:
>>Indeed, but that offset "it should be a multiple of the byte-size of dtype" as the help says.
> My mistake, sorry, even if the help says so, it seems that this is not the case in the actual code. Still, the problem with the size of the available data (which is not necessarily a multiple of dtype byte-size) remains.

Worst case you can always work around such issues with an extra layer
of view manipulation:

# create a raw view onto the contents of the file
file_bytes = np.memmap(path, dtype=np.uint8, ...)
# cut out any arbitrary number of bytes from the beginning and end
data_bytes = file_bytes[...some slice expression...]
# switch to viewing the bytes as the proper data type
data = data_bytes.view(dtype=np.uint32)
# proceed as before


More information about the NumPy-Discussion mailing list