python - numpy.savetxt() outputs very large files -
python - numpy.savetxt() outputs very large files -
i using numpy.savetxt() write numpy array csv file, file generated large. example, if create zeros array:
import numpy test = numpy.zeros((10000,10000), dtype=numpy.float32) numpy.savetxt('c:/datatest.csv',test,delimiter=',')
i expect file around 10,000*10,000*4 bytes (400 mb) large. (this test.nbytes
returns). however, file 2.3 gb large. there reason big file size? looked through numpy documentation, there doesn't seem way specify variable type when writing file. tried other file types/delimiters, same results.
the size of native datatype differs size of string representation of datatype.
numpy.savetxt
has fmt
argument defaults '%.18e'
, formats each of zeros 0.000000000000000000e+00
. 24 characters per item plus 1 delimiter.
to smaller file can alter format (beware of losing important digits) or utilize numpy.save
save in binary or numpy.savez
save compressed archive.
python arrays file-io numpy
Comments
Post a Comment