Reading 32 bit signed ieee 754 floating points from a binary file with python?

前端 未结 3 1054
傲寒
傲寒 2020-12-30 00:35

I have a binary file which is simple a list of signed 32 bit ieee754 floating point numbers. They are not separated by anything, and simply appear one after another until EO

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-30 01:04

    struct.unpack('f', file.read(4))
    

    You can also unpack several at once, which will be faster:

    struct.unpack('f'*n, file.read(4*n))
    

提交回复
热议问题