本文簡要介紹 python 語言中 scipy.io.matlab.whosmat
的用法。
用法:
scipy.io.matlab.whosmat(file_name, appendmat=True, **kwargs)#
列出 MATLAB 文件內的變量。
- file_name: str
mat文件的名稱(如果appendmat==True則不需要.mat擴展名)也可以傳遞打開的file-like對象。
- appendmat: 布爾型,可選
如果不存在,則將 .mat 擴展名附加到給定文件名的末尾。默認為真。
- byte_order: str 或無,可選
默認情況下無,暗示從 mat 文件中猜測的字節順序。否則可以是(‘native’、'='、‘little’、'<'、'BIG'、'>')之一。
- mat_dtype: 布爾型,可選
如果為 True,則返回與加載到 MATLAB 相同 dtype 的數組(而不是保存它們的 dtype)。
- squeeze_me: 布爾型,可選
是否壓縮單位矩陣維度。
- chars_as_strings: 布爾型,可選
是否將 char 數組轉換為字符串數組。
- matlab_compatible: 布爾型,可選
返回將由 MATLAB 加載的矩陣(暗示 squeeze_me=False、chars_as_strings=False、mat_dtype=True、struct_as_record=True)。
- struct_as_record: 布爾型,可選
是否將 MATLAB 結構加載為 NumPy 記錄數組,或者加載為 dtype=object 的 old-style NumPy 數組。將此標誌設置為 False 會複製 SciPy 版本 0.7.x 的行為(返回 numpy 對象數組)。默認設置為 True,因為它可以更輕鬆地 round-trip 加載和保存 MATLAB 文件。
- variables: 元組列表
元組列表,其中每個元組保存矩陣名稱(字符串)、其形狀(整數元組)及其數據類(字符串)。可能的數據類有:int8、uint8、int16、uint16、int32、uint32、int64、uint64、single、double、cell、struct、object、char、sparse、function、opaque、logic、unknown。
參數 ::
返回 ::
注意:
支持 v4(1.0 級)、v6 和 v7 到 7.2 的 matfile。
您將需要 HDF5 python 庫來讀取 matlab 7.3 格式的 mat 文件(例如 h5py)。由於SciPy沒有提供,因此我們在這裏不實現HDF5 /7.3接口。
例子:
>>> from io import BytesIO >>> import numpy as np >>> from scipy.io import savemat, whosmat
創建一些數組,並使用
savemat
將它們寫入BytesIO
實例。>>> a = np.array([[10, 20, 30], [11, 21, 31]], dtype=np.int32) >>> b = np.geomspace(1, 10, 5) >>> f = BytesIO() >>> savemat(f, {'a': a, 'b': b})
使用
whosmat
檢查f
。輸出列表中的每個元組給出了f
中數組的名稱、形狀和數據類型。>>> whosmat(f) [('a', (2, 3), 'int32'), ('b', (1, 5), 'double')]
相關用法
- Python SciPy matlab.loadmat用法及代碼示例
- Python SciPy matlab.savemat用法及代碼示例
- Python SciPy mstats.trim用法及代碼示例
- Python SciPy mstats.winsorize用法及代碼示例
- Python SciPy mstats.argstoarray用法及代碼示例
- Python SciPy misc.ascent用法及代碼示例
- Python SciPy mstats.trima用法及代碼示例
- Python SciPy mstats.tmin用法及代碼示例
- Python SciPy misc.derivative用法及代碼示例
- Python SciPy mstats.tmax用法及代碼示例
- Python SciPy mstats.kruskalwallis用法及代碼示例
- Python SciPy mstats.sem用法及代碼示例
- Python SciPy mstats.zscore用法及代碼示例
- Python SciPy mstats.zmap用法及代碼示例
- Python SciPy mstats.mode用法及代碼示例
- Python SciPy misc.face用法及代碼示例
- Python SciPy mstats.hmean用法及代碼示例
- Python SciPy mstats.variation用法及代碼示例
- Python SciPy mstats.compare_medians_ms用法及代碼示例
- Python SciPy misc.central_diff_weights用法及代碼示例
- Python SciPy mstats.gmean用法及代碼示例
- Python SciPy mstats.pearsonr用法及代碼示例
- Python SciPy mstats.kruskal用法及代碼示例
- Python SciPy mstats.tmean用法及代碼示例
- Python SciPy mstats.mquantiles用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.io.matlab.whosmat。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。