如何使用python打开大尾数编码(ieee-be?

问题描述 投票:0回答:1

我有这个可以打开.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

python numpy file binary endianness
1个回答
0
投票

所以最后比这更轻松:

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。

希望这对某人有用。

© www.soinside.com 2019 - 2024. All rights reserved.