Closed
Description
When saving a large array (>= 2,097,152 doubles), the tofile
function creates a file twice the size of the data, and the first half of the file is all zeros. This occurs only in the append file mode ("ab"
).
My system:
Linux 4.8.10-1-ARCH x86_64
Python 3.5.2
numpy.version.version == '1.11.2'
Code to reproduce:
import numpy
def foo(n, file, mode):
m = numpy.random.rand(n)
open(file, "wb").close() # delete old file contents
f = open(file, mode)
m.tofile(f)
f.close()
n = numpy.fromfile(open(file, "rb"))
print("correct" if numpy.array_equal(m, n) else "incorrect")
foo(2097151, "f1", "ab") # correct
foo(2097152, "f2", "ab") # incorrect
foo(2097152, "f3", "wb") # correct```