我在用Jupyter Lab!
我使用hdf5storage打开了一个'.mat‘文件。此文件由操作数据采集仪的软件生成(ADCP by Rowe,谁可能会问!海洋方面的东西...)
我可以访问密钥并从除一个密钥之外的所有密钥提取数据...'Gps‘包含纬度和经度数据,假设是两列多行的数组……但它的形状是(1x1),当我打印它时,我可以看到数据,但不知道如何访问它!
如何访问此数据?
文件在这里...
https://drive.google.com/file/d/15JEA5y5_Zt52FpPa--Cp_wwl2TYrnlQZ/view?usp=sharing
这是笔记本(屏幕上显示的东西),但你可以明白我的意思。

发布于 2021-03-05 06:30:43
看起来像是‘旧’风格的MATLAB mat文件,我可以用scipy.io.loadmat加载它
In [3]: data = io.loadmat('../Downloads/ADP_1911041032.mat')
In [5]: data['__header__']
Out[5]: b'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Fri Dec 06 10:01:19 2019'
In [6]: data['Gps']
Out[6]:
array([[(array([[-32.05298353, -32.0529503 , -32.0528978 , -32.05284081,
-32.05270699, -32.05265406, -32.05266599, -32.05267098,
-32.05268485, -32.05271432, -32.0526721 , -32.05260368,
-32.05254208, -32.05249182, -32.05245293, -32.05241743,
...
-52.04648597, -52.0463069 , -52.04610979, -52.04591461,
-52.04569035, -52.04549773, -52.04532165]])) ]],
dtype=[('lat', 'O'), ('lon', 'O')])
In [7]: gps=data['Gps']
In [8]: gps.shape
Out[8]: (1, 1)
In [9]: gps.dtype
Out[9]: dtype([('lat', 'O'), ('lon', 'O')])
In [10]: gps[0,0].shape
Out[10]: ()
In [11]: gps[0,0]['lat'].shape
Out[11]: (1, 103)
In [12]: gps[0,0]['lat'].dtype
Out[12]: dtype('<f8')loadmat将MATLAB单元格和结构转换为numpy数组对象。在这里,它返回一个(1,1)形数组(MATLAB始终为2+d),其中包含一个复合dtype,两个字段
In [13]: gps[0,0]['lat']
Out[13]:
array([[-32.05298353, -32.0529503 , -32.0528978 , -32.05284081,
-32.05270699, -32.05265406, -32.05266599, -32.05267098,
-32.05268485, -32.05271432, -32.0526721 , -32.05260368,
...
-32.0491144 , -32.04907168, -32.04903315]])gps.item()[0]返回相同的数组。
基本上,您需要关注shape和dtype,并准备好一步一步地“向下”完成结构。它有助于理解numpy数组、结构和对象。
https://stackoverflow.com/questions/66477232
复制相似问题