如何用python打开big endian编码(ieee-be)?

How to open big endian encoding (ieee-be) with python?

我有这个打开 .eeg 文件的 matlab 代码:

f_in=fopen(a_eegfile,'r','ieee-be');% open file where eeg data are with Big-endian encoding

它给了我一个双精度的一维矩阵。 (793456x1)

我正在尝试用 python 和 numpy 做同样的事情:

data_f = np.fromfile(os.path.join(root,folder,filename), dtype='>f8')

它有效,但我根本没有得到相同的矩阵。 可能是 dtype 参数有问题,但我找不到它。

有人可以帮忙吗?

参见:

https://numpy.org/doc/stable/reference/arrays.dtypes.html#arrays-dtypes-constru

https://fr.mathworks.com/help/matlab/ref/fopen.html#btrnibn-1-machinefmt

所以最后比这更容易:

with open(os.path.join(root,folder,filename),'rb') as file:
    data = file.read()
    data_f = np.array([x for x in data])

data_f 现在存储我的 (793456x1) 整数矩阵。

print(type(data_f),len(data_f), data_f.dtype)

给我:

<class 'numpy.ndarray'> 16695840 int32

将 np 作为 numpy。

希望这对某人有用。