I have a numpy.ndarray
sample of numbers, each between 1 and 2**20
.
I'd like to write it into a binary file, such that each element is represented by four bytes.
However, the resulting file size is different from 4 times the size of the sample.
This is the code I'm using:
outputFile = open('testDS', 'w')
print len(sample)
if (outputFile is not None):
for s in sample:
assert(s < 2**20)
r = struct.pack("i", s)
assert(len(r) == 4)
outputFile.write(r)
outputFile.close()
The output I'm getting (the size of the sample) is: 1000
However, the resulting file size is 4026 bytes.
Any ideas why the file size is not exactly 4000 bytes?