0
我在Matlab中编写代码的一部分,然后进入python。在Matlab我有这样将Matlab转换为Python标签
labels=[1 2 49 49 50 50 51];
和在Python标签我需要加载到have`labels = [ '1', '2', '49', '49', '50', '50' ?,'51' ]
我怎样努力 o1 = scipy.io.loadmat('labels.mat') labels1=np.array(o1['labels'])
但我得到
[[array([[1]], dtype=uint8) array([[1]], dtype=uint8)
array([[1]], dtype=uint8) array([[2]], dtype=uint8)
array([[2]], dtype=uint8) array([[2]], dtype=uint8)
array([[49]], dtype=uint8) array([[49]], dtype=uint8)
array([[49]], dtype=uint8) array([[50]], dtype=uint8)
array([[50]], dtype=uint8) array([[50]], dtype=uint8)
array([[51]], dtype=uint8) array([[51]], dtype=uint8)
array([[51]], dtype=uint8) array([[52]], dtype=uint8)
array([[52]], dtype=uint8) array([[52]], dtype=uint8)
array([[53]], dtype=uint8) array([[53]], dtype=uint8)
array([[53]], dtype=uint8) array([[54]], dtype=uint8)
array([[54]], dtype=uint8) array([[54]], dtype=uint8)]]
我需要这个,因为这些都是下一步标签:
Y=pdist(X, 'correlation')
Z=hierarchy.linkage(Y, method='complete', metric='correlation')
row_dendr = hierarchy.dendrogram(Z, labels=labels1)
我可以用Matlab以其他方式将它保存起来吗?我在循环中制作的那些标签,因此它是一个很大的向量。 如果键入onlu打印O1我得到:
{'__header__': b'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Fri May 13 20:11:14 2016', '__version__': '1.0', 'labels': array([[array([[1]], dtype=uint8), array([[1]], dtype=uint8),
array([[1]], dtype=uint8), array([[2]], dtype=uint8),
array([[2]], dtype=uint8), array([[2]], dtype=uint8),
array([[49]], dtype=uint8), array([[49]], dtype=uint8),
array([[49]], dtype=uint8), array([[50]], dtype=uint8),
array([[50]], dtype=uint8), array([[50]], dtype=uint8),
array([[51]], dtype=uint8), array([[51]], dtype=uint8),
array([[51]], dtype=uint8), array([[52]], dtype=uint8),
array([[52]], dtype=uint8), array([[52]], dtype=uint8),
array([[53]], dtype=uint8), array([[53]], dtype=uint8),
array([[53]], dtype=uint8), array([[54]], dtype=uint8),
array([[54]], dtype=uint8), array([[54]], dtype=uint8)]], dtype=object), '__globals__': []}
我从来没有使用scipy.io.loadmat功能,但看着文档,它会返回一个字典。如果你输入'print o1',你会得到什么?如果它确实正在返回一本字典,我想你可能只能从这些值中提取数据 - 看起来你只是想要一个列表。 – flyingmeatball
我编辑了我的帖子! –
它看起来像你放入matlab中的标签与你正在阅读的python不匹配...你确定这些标签反映了你正在阅读的内容吗? – flyingmeatball