While numpy.ndarray.fromfile()
allows you to specify a binary format for reading (for example, 'f' for float), the .tofile()
function does not have such binary options. This is a very inconvenient inconsistency for those of us who need to write binaries in a specific format to read other software. Unfortunately, this issue seems to be ignored by the developer community, as there seems to be no open ticket.
I created a simple replace function using an array module. The main code looks something like this:
def fwrite(filename, formatstring, ndarray): arr = array.array(formatstring, ndarray.flatten()) f = open(filename, 'w') arr.tofile(f) f.close()
While this is working. Obviously this can / should be embellished with bugs, etc.
source share