我是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)
答案 0 :(得分:1)
尝试将最后一行更改为:
for k in mat.keys():
if not k.startswith('__'):
print(k + " " + mat[k].dtype.name + " " + str(mat[k].shape))