显示 Python 中加载的 Mat 文件的类型和大小
Showing Type and Size of a Mat file loaded in Python
我是 python 的新手,我正在将 Matlab 代码转换为 Python。我已经加载了 mat 文件,它是 Python 中的字典。我可以打印键名,但我无法理解如何显示值的类型和大小
import scipy.io
import os
import sys
os.path.dirname(os.path.realpath(__file__))
path = os.getcwd();
filename = "\mnist_uint8"
fullname = path+filename;
print("Reading file:"+fullname)
try:
mat = scipy.io.loadmat(fullname)
except IOError as err:
print ("I/O error({0}): {1}".format(e.errno, e.strerror))
sys.exit();
else:
print("Successfully loaded mat file")
keys = mat.keys()
for key in keys:
print(key)
我需要看下面的 "key " + "type" + "size"
尝试将最后一行更改为:
for k in mat.keys():
if not k.startswith('__'):
print(k + " " + mat[k].dtype.name + " " + str(mat[k].shape))
我是 python 的新手,我正在将 Matlab 代码转换为 Python。我已经加载了 mat 文件,它是 Python 中的字典。我可以打印键名,但我无法理解如何显示值的类型和大小
import scipy.io
import os
import sys
os.path.dirname(os.path.realpath(__file__))
path = os.getcwd();
filename = "\mnist_uint8"
fullname = path+filename;
print("Reading file:"+fullname)
try:
mat = scipy.io.loadmat(fullname)
except IOError as err:
print ("I/O error({0}): {1}".format(e.errno, e.strerror))
sys.exit();
else:
print("Successfully loaded mat file")
keys = mat.keys()
for key in keys:
print(key)
我需要看下面的 "key " + "type" + "size"
尝试将最后一行更改为:
for k in mat.keys():
if not k.startswith('__'):
print(k + " " + mat[k].dtype.name + " " + str(mat[k].shape))