Re: Writing some floats in a file in an efficient way

2018-02-22 Thread ast
Le 21/02/2018 à 18:23, bartc a écrit : On 21/02/2018 15:54, ast wrote: Le 21/02/2018 à 15:02, bartc a écrit : On 21/02/2018 13:27, ast wrote: Time efficient or space efficient? space efficient If the latter, how many floats are we talking about? 10^9 Although it might be better

Re: Writing some floats in a file in an efficient way

2018-02-21 Thread bartc
On 21/02/2018 15:54, ast wrote: Le 21/02/2018 à 15:02, bartc a écrit : On 21/02/2018 13:27, ast wrote: Time efficient or space efficient? space efficient If the latter, how many floats are we talking about? 10^9 OK. My experiment of writing the same 64-bit float a billion times to a

Re: Writing some floats in a file in an efficient way

2018-02-21 Thread ast
Le 21/02/2018 à 14:27, ast a écrit : struct.pack() as advised works fine. Exemple: >>> import struct >>> struct.pack(">d", -0.0) b'\x80\x00\x00\x00\x00\x00\x00\x00' before I read your answers I found a way with pickle >>> import pickle >>> pickle.dumps(-0.0)[3:-1] b'\x80\x00\x00\x00\x00\x00\x0

Re: Writing some floats in a file in an efficient way

2018-02-21 Thread ast
Le 21/02/2018 à 15:02, bartc a écrit : On 21/02/2018 13:27, ast wrote: Time efficient or space efficient? space efficient If the latter, how many floats are we talking about? 10^9 -- https://mail.python.org/mailman/listinfo/python-list

Re: Writing some floats in a file in an efficient way

2018-02-21 Thread Peter Heitzer
ast wrote: >Hello >I would like to write a huge file of double precision >floats, 8 bytes each, using IEEE754 standard. Since >the file is big, it has to be done in an efficient >way. >I tried pickle module but unfortunately it writes >12 bytes per float instead of just 8. >Is there a way to wr

Re: Writing some floats in a file in an efficient way

2018-02-21 Thread Peter Otten
ast wrote: > Is there a way to write a float with only 8 bytes ? If you want to write the values one-by-one convert them to bytes with struct.pack() and then write the result. To write many values at once use array.array.tofile() or numpy.array.tofile(). -- https://mail.python.org/mailman/l

Re: Writing some floats in a file in an efficient way

2018-02-21 Thread bartc
On 21/02/2018 13:27, ast wrote: Hello I would like to write a huge file of double precision floats, 8 bytes each, using IEEE754 standard. Since the file is big, it has to be done in an efficient way. Time efficient or space efficient? If the latter, how many floats are we talking about? I t