-
-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Description
A major use case for the numpy.fromfile() function is in reading from binary file of some kind. Frequently, binary formats are just arrays of data with a fixed-size header. It would be useful to have an extra optional parameter for the fromfile() function which defines a byte offset for when to start reading. This parameter would default to 0, leaving it backwards-compatible with existing code.
Reproducing code example:
import numpy as np
binary_file = "sample_binary.bin"
my_array = np.fromfile(binary_file, dtype=np.uint8, offset=40)
Currently, the above code will not run, as the 'offset' keyword argument is not supported. In this call, the ndarray object 'my_array' would be the result of the binary file being read in, starting with an offset of 40 bytes.
It is certainly possible to work-around the issue currently, but adding direct support for offsets in the function would make for cleaner code.