What is the equivalent of 'fread' from Matlab in Python?

后端 未结 4 1060
生来不讨喜
生来不讨喜 2020-12-14 21:35

I have practically no knowledge of Matlab, and need to translate some parsing routines into Python. They are for large files, that are themselves divided into \'blocks\', an

4条回答
  •  遥遥无期
    2020-12-14 21:42

    Really though, I want to know how to replicate [A, count] = fread(fid, 3, 'uint32');

    In Matlab, one of fread()'s signatures is fread(fileID, sizeA, precision). This reads in the first sizeA elements (not bytes) of a file, each of a size sufficient for precision. In this case, since you're reading in uint32, each element is of size 32 bits, or 4 bytes.

    So, instead, try io.readline(12) to get the first 3 4-byte elements from the file.

提交回复
热议问题