scipy.io.loadmat()没有返回字典

时间:2013-12-14 12:58:58

标签: python scipy

我一直在努力用scipy处理现实挖掘数据集。

loadmat()方法没有返回字典。

Python代码 http://dl.dropboxusercontent.com/u/1800572/blog/parse_network.py

数据集:http://realitycommons.media.mit.edu/RealityMining.zip

我在数据集上运行脚本时出现此错误。 AttributeError(numpy.void)my_hashedNumber没有这样的属性。

1 个答案:

答案 0 :(得分:2)

为什么你认为这个loadmat对象没有字典?错误发生在:

def get_events(matlab_obj):
    ...
    subjects = matlab_obj["s"][0]
    ...
    for subject_object in subjects:
        try:
            subject_hash = subject_object.my_hashedNumber[0][0]  # AttributeError here

matlab_obj["s"]成功访问加载的对象作为字典。 subjects是一个形状为(106,)的numpy记录数组,以及58个字段。访问其中一个字段的正确方法是:subject_object['my_hashedNumber']

如果字段是多维的,则应使用[0,0]编制索引,而不是[0][0]